常规来说GameObject.Find(yourname)只存在于物体还存在的情况下,也就是active情况下,当已经设置为false时就不能获取到了,现在要做的就是在物体active属性设置为false前获取gameobgect把它存储到全局变量中,全局变量设置如下
List<GameObject> gbList = new List<GameObject>();
在开始方法中赋值
void Start () {
for(int i=1;i<gbnames.Length;i++)
{
gb = GameObject.Find(gbnames[i]);
gbList.Add(gb);
gb.SetActive(false);//2018版本新方法 设置物体可见性
}
InvokeRepeating("replay", 0f, 10f);
}
然后在其他地方尽情调用
void Update () {
if (gbList[indexPlay].activeSelf == false)
{
gbList[indexPlay].SetActive(true);
}
}
完工