public void FindNearAuxinsAlt() { List <AuxinController> aux = new List <AuxinController>(); List <GameObject> tmep = new List <GameObject>(); myAuxins.Clear(); Collider[] hitCollider = Physics.OverlapSphere(transform.position, agentRadius); foreach (Collider c in hitCollider) { if (c.gameObject.tag == "Cell") { aux.AddRange(c.gameObject.GetComponent <CellController>().GetAuxins()); } } foreach (AuxinController a in aux) { GameObject newAuxin = Instantiate(Auxin, a.position, Quaternion.identity) as GameObject; newAuxin.name = a.name; newAuxin.GetComponent <TempAuxin>().taken = a.taken; newAuxin.GetComponent <TempAuxin>().SetAgent(a.GetAgent()); newAuxin.GetComponent <TempAuxin>().SetMinDistance(a.GetMinDistance()); tmep.Add(newAuxin); } Collider[] outer = Physics.OverlapSphere(transform.position, agentRadius); foreach (Collider c in outer) { if (c.gameObject.tag == "Auxin") { if (c.gameObject.GetComponent <TempAuxin>().taken) { GameObject otherAgent = c.gameObject.GetComponent <TempAuxin>().GetAgent(); otherAgent.GetComponent <AgentController>().myAuxins.Remove(AuxinController.GetAuxinName(c.gameObject.name)); } AuxinController.GetAuxinName(c.gameObject.name).taken = true; AuxinController.GetAuxinName(c.gameObject.name).SetAgent(this.gameObject); myAuxins.Add(AuxinController.GetAuxinName(c.gameObject.name)); } } foreach (GameObject g in tmep) { Destroy(g); } }
//add a new auxin on myAuxins public void AddAuxin(AuxinController auxin) { myAuxins.Add(auxin); }