public GameObject img1; public GameObject img2; public GameObject img3; public GameObject MOve; public GameObject Rotate; public GameObject Scale; public void Move() { if(MOve.GetComponent<MOVEWIN>().enabled == false) { img1.SetActive(true); MOve.GetComponent<MOVEWIN>().enabled = true; img2.SetActive(false); Rotate.GetComponent<Rotet>().enabled = false; img3.SetActive(false); GameObject[] enemies = GameObject.FindGameObjectsWithTag("MOVEWIN"); foreach (GameObject Scale in enemies) { Destroy(Scale.GetComponent<Scale>()); } } else { img1.SetActive(false); MOve.GetComponent<MOVEWIN>().enabled = false; } } public void Rota() { if (Rotate.GetComponent<Rotet>().enabled == false) { img2.SetActive(true); Rotate.GetComponent<Rotet>().enabled = true; img1.SetActive(false); MOve.GetComponent<MOVEWIN>().enabled = false; img3.SetActive(false); GameObject[] enemies = GameObject.FindGameObjectsWithTag("MOVEWIN"); foreach (GameObject Scale in enemies) { Destroy(Scale.GetComponent<Scale>()); } } else { img2.SetActive(false); Rotate.GetComponent<Rotet>().enabled = false; } } public void Scalse() { GameObject[] enemies = GameObject.FindGameObjectsWithTag("MOVEWIN"); foreach (GameObject Scale in enemies) { if (Scale.GetComponent<Scale>() == null) { img3.SetActive(true); Scale.AddComponent<Scale>(); img1.SetActive(false); MOve.GetComponent<MOVEWIN>().enabled = false; img2.SetActive(false); Rotate.GetComponent<Rotet>().enabled = false; unity 整理代码 功能不变 缩短
时间: 2024-02-14 21:22:17 浏览: 90
Unity3D如何获得两GameObject间距1
public GameObject img1, img2, img3, MOve, Rotate, Scale;
public void Move()
{
if (MOve.GetComponent<MOVEWIN>().enabled == false)
{
img1.SetActive(true);
MOve.GetComponent<MOVEWIN>().enabled = true;
img2.SetActive(false);
Rotate.GetComponent<Rotet>().enabled = false;
img3.SetActive(false);
DestroyExistingComponentsWithTag("MOVEWIN", typeof(Scale));
}
else
{
img1.SetActive(false);
MOve.GetComponent<MOVEWIN>().enabled = false;
}
}
public void Rota()
{
if (Rotate.GetComponent<Rotet>().enabled == false)
{
img2.SetActive(true);
Rotate.GetComponent<Rotet>().enabled = true;
img1.SetActive(false);
MOve.GetComponent<MOVEWIN>().enabled = false;
img3.SetActive(false);
DestroyExistingComponentsWithTag("MOVEWIN", typeof(Scale));
}
else
{
img2.SetActive(false);
Rotate.GetComponent<Rotet>().enabled = false;
}
}
public void Scalse()
{
DestroyExistingComponentsWithTag("MOVEWIN", typeof(Scale));
if (Scale == null)
{
img3.SetActive(true);
Scale.AddComponent<Scale>();
img1.SetActive(false);
MOve.GetComponent<MOVEWIN>().enabled = false;
img2.SetActive(false);
Rotate.GetComponent<Rotet>().enabled = false;
}
}
void DestroyExistingComponentsWithTag(string tag, System.Type type)
{
GameObject[] existingObjects = GameObject.FindGameObjectsWithTag(tag);
foreach (GameObject obj in existingObjects)
{
Component component = obj.GetComponent(type);
if (component != null)
{
Destroy(component);
}
}
}
阅读全文