Advertisement
jyourman

Untitled

Aug 27th, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 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.  
  17. //store the existing TimerController
  18. TimerController timerController;
  19.  
  20. void Start ()
  21. {
  22. rb = GetComponent<Rigidbody>();
  23. count = 0;
  24. SetCountText ();
  25. winText.text = "";
  26.  
  27.  
  28. //get that TimerController
  29. timerController = GameObject.FindObjectOfType<TimerController>(); //use this if there's only one - otherwise find it by tag or gameobject name
  30.  
  31. //set the level's duration
  32. timerController.SetTimer(60.0f);
  33.  
  34. //start the timer ... if this is where you want it to start
  35. timerController.StartTimer();
  36. }
  37.  
  38. void FixedUpdate()
  39. {
  40. float moveHorizontal = Input.GetAxis ("Horizontal");
  41. float moveVertical = Input.GetAxis ("Vertical");
  42.  
  43. Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
  44.  
  45. rb.AddForce (movement * speed);
  46. }
  47.  
  48. void OnTriggerEnter(Collider other) //whole thing sent to game controller
  49. {
  50. if (other.gameObject.CompareTag("Pick Up"))
  51. {
  52. other.gameObject.SetActive (false);
  53. count = count + 1;
  54. SetCountText ();
  55.  
  56. //now you can add time to the timer like you want
  57. timerController.AddToTimer(3f);
  58. }
  59. }
  60.  
  61. void SetCountText ()
  62. {
  63. countText.text = "Count: " + count.ToString ();
  64. if (count >= 19)
  65. {
  66. winText.text = "You Won";
  67. }
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement