using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class PlayerController : MonoBehaviour {
public float speed;
public Text countText;
public Text winText;
public Text text;
private Rigidbody rb;
private int count;
float timeLeft = 30.0f;
void Start ()
{
rb = GetComponent
count = 0;
SetCountText ();
winText.text = "";
}
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)
{
if (other.gameObject.CompareTag ("Pick Up"))
{
other.gameObject.SetActive (false);
count = count + 1;
SetCountText ();
}
}
void SetCountText ()
{
countText.text = "Count: " + count.ToString ();
if (count >= 13)
{
winText.text = "You Win!";
}
}
void Update()
{
timeLeft -= Time.deltaTime;
text.text = "Time Left:" + Mathf.Round (timeLeft);
if (timeLeft < 0)
{
SceneManager.LoadScene ("gameOver");
}
}
}
No comments:
Post a Comment