using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class score : MonoBehaviour { public int score2 = 30; public GameObject img_Over; bool gameover = false; public void showScore(int point) { score2 += point; if(score2 < 0 && gameover ==false) { gameover = true; //播放過關失敗音效 this.GetComponent().Play(); img_Over.SetActive(true); } //注意:如果沒有using UnityEngine.UI;就無法抓到參數Text GameObject.Find("Text_energy").GetComponent().text = "體力:" + score2.ToString(); } }