using System.Collections; using System.Collections.Generic; using UnityEngine; public class ball : MonoBehaviour { float movementSpeed=5.0f; int num = 3; string output= "Gem numbers = 3"; // Rigidbody ufo1; // Start is called before the first frame update private Rigidbody rb; void Start() { // ufo1 = GameObject.Find("UFO").GetComponent(); rb = GetComponent (); } // Update is called once per frame void Update() { float x1 = Input.GetAxis("Horizontal"); float z1 = Input.GetAxis("Vertical"); rb.AddForce (x1,0f,z1,ForceMode.Acceleration); } void OnTriggerEnter (Collider other) { if (other.tag == "Picker") { num--; output = "Gem numbers = " + num.ToString(); if (num == 0) output = "你贏了!"; Destroy (other.gameObject); } } void OnGUI() { GUI.Box(new Rect(15, 15, 150, 50),""); GUI.Label(new Rect(25, 25, 130, 40), output); } }