//其它元素离开 void OnTriggerExit2D(Collider2D other) { YaElement exitElement = other.GetComponent <YaElement> (); stayElement.Remove(exitElement); //电 ElementElectric exitElectric = other.GetComponent <ElementElectric> (); stayElectric.Remove(exitElectric); }
//其它元素介入 void OnTriggerEnter2D(Collider2D other) { YaElement enterElement = other.GetComponent <YaElement> (); if (enterElement != null) { if (!stayElement.Contains(enterElement) && enterElement != this) { stayElement.Add(enterElement); } } //电 ElementElectric electric = other.GetComponent <ElementElectric> (); if (electric != null) { if (!stayElectric.Contains(electric) && electric != this) { stayElectric.Add(electric); } } }