void OnCollisionEnter(Collision coll) { if (trigUpdate == true) //one interaction at a time { return; } if (coll.gameObject.tag == "BasicCell") { //GameObject cellOther = coll.gameObject; //BasicCellProperty cellOtherProperty = coll.gameObject.GetComponent<BasicCellProperty> (); CellProperty_Global otherStats = coll.gameObject.GetComponent <CellProperty_Global>(); cellStats.setVector(cellStats.getVector() * -1); if (cellStats.getEnergy() <= otherStats.getEnergy()) //if other cell has more energy increase own energy { cellStats.alterEnergy(1); } else if (cellStats.getEnergy() > 0) //if other cell has less energy and we have energy, reduce own energy { cellStats.alterEnergy(-1); } if (cellStats.getEnergy() >= 20) { cellStats.setEnergy(0); GameObject newCell = (GameObject)Instantiate(nextGen, new Vector3(transform.position.x, transform.position.y, transform.position.z), Quaternion.identity); cellStats.copy(newCell.GetComponent <CellProperty_Global> ()); Destroy(this.gameObject); } } if (coll.gameObject.tag == "FeederCell") { cellStats.setVector(cellStats.getVector() * -1); } trigUpdate = true; }
void OnCollisionEnter(Collision coll) { if (coll.gameObject.tag == "BasicCell") { CellProperty_Global otherStats = coll.gameObject.GetComponent <CellProperty_Global> (); if (otherStats.getEnergy() > 0) { otherStats.alterEnergy(-1); cellStats.alterEnergy(1); } if (cellStats.getEnergy() >= 10) { cellStats.setEnergy(0); GameObject child = (GameObject)Instantiate(offspring, new Vector3(transform.position.x, transform.position.y + 1, transform.position.z), Quaternion.identity); CellProperty_Global childproperty = child.GetComponent <CellProperty_Global> (); switch (Random.Range(1, 4)) { case 1: childproperty.setVector(Vector3.left); break; case 2: childproperty.setVector(Vector3.right); break; case 3: childproperty.setVector(Vector3.forward); break; case 4: childproperty.setVector(Vector3.back); break; } childproperty.setSpeed(1); } } }