Advertisement
jyourman

Untitled

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