Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.UI;
- using System.Collections;
- public class PlayerController : MonoBehaviour {
- public float speed;
- public Text countText;
- public Text winText;
- private Rigidbody rb;
- private int count;
- //store the existing TimerController
- TimerController timerController;
- void Start ()
- {
- rb = GetComponent<Rigidbody>();
- count = 0;
- SetCountText ();
- winText.text = "";
- //get that TimerController
- timerController = GameObject.FindObjectOfType<TimerController>(); //use this if there's only one - otherwise find it by tag or gameobject name
- //set the level's duration
- timerController.SetTimer(60.0f);
- //start the timer ... if this is where you want it to start
- timerController.StartTimer();
- }
- void FixedUpdate()
- {
- float moveHorizontal = Input.GetAxis ("Horizontal");
- float moveVertical = Input.GetAxis ("Vertical");
- Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
- rb.AddForce (movement * speed);
- }
- void OnTriggerEnter(Collider other) //whole thing sent to game controller
- {
- if (other.gameObject.CompareTag("Pick Up"))
- {
- other.gameObject.SetActive (false);
- count = count + 1;
- SetCountText ();
- //now you can add time to the timer like you want
- timerController.AddToTimer(3f);
- }
- }
- void SetCountText ()
- {
- countText.text = "Count: " + count.ToString ();
- if (count >= 19)
- {
- winText.text = "You Won";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement