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 Movement : MonoBehaviour {
- public float speed;
- private int score;
- private Rigidbody rb;
- public Text scoreText;
- // Use this for initialization
- void Start () {
- rb = GetComponent<Rigidbody> ();
- score = 0;
- }
- // Update is called once per frame
- void Update () {
- 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 ("Collect Me")) {
- other.gameObject.SetActive (false);
- score = score + 1;
- SetScoreText ();
- if (score >= 3) {
- scoreText.text = "You won!";
- }
- }
- }
- //---------------------------------
- void SetScoreText()
- {
- scoreText.text = "Score: " + score.ToString ();
- }
- //---------------------------------
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement