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); } } }
public void copy(CellProperty_Global copyTo) { copyTo.setEnergy(this.getEnergy()); copyTo.setSpeed(this.getSpeed()); copyTo.setVector(this.getVector()); }