很基本的功能,
不過在做視野拉大自動把所有單位細節UI隱藏的功能時還翻了一下,
這種做法很吃效能,只能放在像玩家手動操作視野範圍這種由玩家觸發的行動上,
請不要放在update之類的地方,
多數理想情況還是要隨時把程式物件拿在手上,
不過單位多的話偶爾也需要用這種硬性的遍歷物件。
public void 更新所有單位狀態UI()
{
GameObject[] obj = FindObjectsOfType(typeof(GameObject)) as GameObject[];
foreach (GameObject 物件 in obj)
{
//Debug.Log(物件.gameObject.name);
itemBasic 單位腳本 = 物件.GetComponent<itemBasic>();
if (單位腳本 != null)
{
單位腳本.更新單位名稱等級();
單位腳本.更新單位狀態("");
單位腳本.血量變化(0);
}
}
}
沒有留言:
張貼留言
Love the Lord your God with all your heart and with all your soul and with all your mind.
耶 穌 對 他 說 : 你 要 盡 心 、 盡 性 、 盡 意 愛 主 ─ 你 的 神 。
—— Matthew 22:37 —— 馬 太 福 音 22:37