Advertisement
MrsMcLead

Roll A Ball

Jan 29th, 2018
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.05 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class Movement : MonoBehaviour {
  7.     public float speed;
  8.     private int score;
  9.     private Rigidbody rb;
  10.     public Text scoreText;
  11.  
  12.     // Use this for initialization
  13.     void Start () {
  14.         rb = GetComponent<Rigidbody> ();
  15.         score = 0;
  16.     }
  17.    
  18.     // Update is called once per frame
  19.     void Update () {
  20.         float moveHorizontal = Input.GetAxis ("Horizontal");
  21.         float moveVertical = Input.GetAxis ("Vertical");
  22.  
  23.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
  24.  
  25.         rb.AddForce (movement * speed);
  26.     }
  27.     //---------------------------------
  28.     void OnTriggerEnter(Collider other)
  29.     {
  30.         if (other.gameObject.CompareTag ("Collect Me")) {
  31.             other.gameObject.SetActive (false);
  32.             score = score + 1;
  33.             SetScoreText ();
  34.             if (score >= 3) {
  35.                 scoreText.text = "You won!";
  36.             }
  37.         }
  38.     }
  39.     //---------------------------------
  40.     void SetScoreText()
  41.     {
  42.         scoreText.text = "Score: " + score.ToString ();
  43.     }
  44.     //---------------------------------
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement