Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // cmd + '(mac) / ctrl + '(win) Collider
- using UnityEngine;
- using System.Collections;
- public class PlayerController : MonoBehaviour {
- public float speed;
- public string myString = "Default";
- private int count;
- void Awake () {
- count = 0;
- myString = "Set in Awake!";
- }
- void FixedUpdate () {
- if (Input.GetKey("w")) {
- rigidbody.AddForce (Vector3.forward * speed * Time.deltaTime);
- }
- if (Input.GetKey("s")) {
- rigidbody.AddForce (-Vector3.forward * speed * Time.deltaTime);
- }
- if (Input.GetKey("a")) {
- rigidbody.AddForce (-Vector3.right * speed * Time.deltaTime);
- }
- if (Input.GetKey("d")) {
- rigidbody.AddForce (Vector3.right * speed * Time.deltaTime);
- }
- }
- void OnTriggerEnter(Collider other) {
- if (other.gameObject.tag == "PickUp") {
- other.gameObject.SetActive(false);
- count = count + 1;
- }
- }
- void OnGUI () {
- GUI.Label(new Rect(10, 10, 100, 20), "Count: " + count);
- if (count >= 12) {
- GUI.Label(new Rect(Screen.width / 2 - 50, Screen.height / 3, 100, 20), "YOU WIN!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement