使用相同按钮激活和停用

时间:2016-10-03 15:28:17

标签: c# unity3d

我想创建一个按钮来激活和停用3个游戏对象,但是我没有得到它。这是我正在使用的脚本。有人能帮助我吗?

using UnityEngine;
using System.Collections;

public class OcultarPlayer : MonoBehaviour {

public GameObject objeto1;
public GameObject objeto2;
public GameObject objeto3;

void OnMouseDown() {
    if(objeto1.GetComponent<Renderer>().enabled == true && objeto2.GetComponent<Renderer>().enabled == true && objeto3.GetComponent<Renderer>().enabled == true)
    {
        objeto1.GetComponent<Renderer>().enabled = false;
        objeto2.GetComponent<Renderer>().enabled = false;
        objeto3.GetComponent<Renderer>().enabled = false;
    }

    if (objeto1.GetComponent<Renderer>().enabled = false &&   objeto2.GetComponent<Renderer>().enabled == false && objeto3.GetComponent<Renderer>().enabled == false)
    {
    objeto1.GetComponent<Renderer>().enabled = true;
    objeto2.GetComponent<Renderer>().enabled = true;
    objeto3.GetComponent<Renderer>().enabled = true;
}

}
}

1 个答案:

答案 0 :(得分:1)

做一些更简单的事情:

public Renderer objeto1;
public Renderer objeto2;
public Renderer objeto3;

bool enabled = false;
void OnMouseDown() 
{
    objeto1.enabled = enabled;
    objeto2.enabled = enabled;
    objeto3.enabled = enabled;
    enabled = !enabled;
}