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, 70), ""); GUI.Label(new Rect(25, 25, 130, 30), output); if (num == 0) { if (GUI.Button(new Rect(25, 45, 130, 30), "try again(Y/N)?")) { //Application.LoadLevel("SampleScene"); UnityEngine.SceneManagement.SceneManager.LoadScene(0); //UnityEngine.SceneManagement.SceneManager.LoadScene("SampleScene"); } } } }