Skip to content
Permalink
908de9ccf4
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
52 lines (42 sloc) 1.04 KB
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;
void Start()
{
rb = GetComponent<Rigidbody>();
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 >= 33)
{
wintext.text = "You Win!";
}
}
}