using System.Collections; using System.Collections.Generic; using UnityEngine; public class EffectController : MonoBehaviour { public GameObject[] objects; // 宣告一個陣列來存放要控制的物件 void Update() { if (Input.GetKeyDown(KeyCode.Alpha1)) { SetObjectsActive(true); // 按下鍵盤 1 啟用陣列中的所有物件(測試用) } if (Input.GetKeyDown(KeyCode.Alpha2)) { SetObjectsActive(false); // 按下鍵盤 2 停用陣列中的所有物件(測試用) } } public void EffectsON() { SetObjectsActive(true); } public void EffectsOFF() { SetObjectsActive(false); } void SetObjectsActive(bool isActive) { foreach (GameObject obj in objects) { obj.SetActive(isActive); // 定義一個方法來啟用或停用陣列中的所有物件 } } }