Advertisement
Guest User

Untitled

a guest
Dec 7th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. using System.Collections;
  2.  
  3. public class PlayerController : MonoBehaviour {
  4.  
  5. public float speed;
  6. public Text countText;
  7. public Text WinText;
  8.  
  9. private Rigidbody rb;
  10. private int count;
  11.  
  12. void Start ()
  13. {
  14. rb = GetComponent<Rigidbody>();
  15. count = 0;
  16. SetCountText ();
  17. WinText.text = "";
  18. }
  19.  
  20. void FixedUpdate ()
  21. {
  22. float moveHorizontal = Input.GetAxis ("Horizontal");
  23. float moveVertical = Input.GetAxis ("Vertical");
  24. float jump;
  25.  
  26. if (Input.GetKeyDown(KeyCode.Space))
  27. jump = 12;
  28. else
  29. jump = 0;
  30.  
  31. Vector3 movement = new Vector3 (moveHorizontal, jump, moveVertical);
  32.  
  33. rb.AddForce (movement * speed);
  34. }
  35.  
  36. void OnTriggerEnter(Collider other)
  37. {
  38. if (other.gameObject.CompareTag("PickUp"))
  39. {
  40. other.gameObject.SetActive (false);
  41. count = count + 1;
  42. SetCountText ();
  43. }
  44. }
  45.  
  46. void SetCountText ()
  47. {
  48. countText.text = "Count: " + count.ToString ();
  49. if (count >= 19)
  50. {
  51. WinText.text = "You Win!";
  52. }
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement