Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Movement : MonoBehaviour
- {
- Rigidbody rb;
- public GameObject Player;
- float speed = 0.05f;
- float JumpSpeed = 30f;
- bool PlayerNotJumping;
- Vector3 SpawnPoint = new Vector3(2.61f, 1f, 0.02f);
- public int HP = 5;
- // Use this for initialization
- void Start()
- {
- rb = GetComponent<Rigidbody>();
- }
- // Update is called once per frame
- void Update()
- {
- Controls();
- }
- void Controls()
- {
- Player = GameObject.FindGameObjectWithTag("Player");
- if (HP <= 0)
- {
- HP = 5;
- transform.position = SpawnPoint;
- }
- if (Input.GetKey(KeyCode.A))
- {
- transform.Translate(Vector3.left * speed);
- }
- if (Input.GetKey(KeyCode.D))
- {
- transform.Translate(Vector3.right * speed);
- }
- if(PlayerNotJumping == true)
- {
- if (Input.GetKeyDown(KeyCode.Space))
- {
- Jump();
- }
- }
- }
- void Jump()
- {
- rb.AddForce(Vector3.up * JumpSpeed);
- }
- void OnCollisionEnter(Collision Other)
- {
- if(Other.gameObject.tag == "checkpoint")
- {
- SpawnPoint = new Vector3(-37f, 0.99f, 0);
- }
- if(Other.gameObject.tag == "Checkpoint2")
- {
- SpawnPoint = new Vector3(-86f, 0.99f, 0);
- }
- if (Other.gameObject.tag == "HolyGround")
- {
- PlayerNotJumping = true;
- }
- if (Other.gameObject.tag == "UnholyGround")
- {
- HP -= 5;
- }
- }
- void OnCollisionExit(Collision GroundCollide)
- {
- if(GroundCollide.gameObject.tag == "HolyGround")
- {
- PlayerNotJumping = false;
- }
- }
- }
Add Comment
Please, Sign In to add comment