Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class Player : MonoBehaviour {
- public Rigidbody rid;
- public Vector3 direction;
- public float speed = 100f;
- public int points = 0;
- public Text wintext;
- public Text scoretext;
- // Use this for initialization
- void Start () {
- rid = GetComponent<Rigidbody>();
- scoretext.text = "Score: " + points.ToString();
- wintext.text = "";
- }
- void Update () {
- float h = Input.GetAxis("Horizontal");
- float v = Input.GetAxis("Vertical");
- direction.x = h;
- direction.z = v;
- rid.AddForce(direction.normalized*speed*Time.deltaTime);
- if (points >= 4)
- wintext.text = "WIN!";
- }
- private void OnTriggerEnter(Collider other)
- {
- if (other.CompareTag("cube"))
- {
- points += 1;
- other.gameObject.SetActive(false);
- scoretext.text = "Score: " + points.ToString();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement