Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- public class PlayerController : MonoBehaviour {
- public float speed;
- public Text countText;
- public Text WinText;
- private Rigidbody rb;
- private int count;
- void Start ()
- {
- rb = GetComponent<Rigidbody>();
- count = 0;
- SetCountText ();
- WinText.text = "";
- }
- void FixedUpdate ()
- {
- float moveHorizontal = Input.GetAxis ("Horizontal");
- float moveVertical = Input.GetAxis ("Vertical");
- float jump;
- if (Input.GetKeyDown(KeyCode.Space))
- jump = 12;
- else
- jump = 0;
- Vector3 movement = new Vector3 (moveHorizontal, jump, moveVertical);
- rb.AddForce (movement * speed);
- }
- void OnTriggerEnter(Collider other)
- {
- if (other.gameObject.CompareTag("PickUp"))
- {
- other.gameObject.SetActive (false);
- count = count + 1;
- SetCountText ();
- }
- }
- void SetCountText ()
- {
- countText.text = "Count: " + count.ToString ();
- if (count >= 19)
- {
- WinText.text = "You Win!";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement