public void setDNA(DNAbloop newDNA) { dna = newDNA; maxSpeed = ExtensionMethods.map(dna.genes[0], 0, 1, 10, 0); // MaxSpeed an Size are now mapped to values according to the DNA size = ExtensionMethods.map(dna.genes[0], 0, 1, 0, 2); gameObject.transform.localScale *= size; }
GameObject reproduce() // This function will return a new bloop, the child. { if (Random.Range(0f, 1f) < 0.20) // a 20% chance of executine the code. i.e. a 20% chance of reproducing { DNAbloop childDNA = dna.copy(); // make a copy of the DNA childDNA.mutate(0.001f); // 0.1% mutation rate GameObject bloopObj = GameObject.CreatePrimitive(PrimitiveType.Sphere); // Make an object Bloop bloop = bloopObj.AddComponent <Bloop>(); // Turn it into a bloop! bloop.setDNA(childDNA); bloopObj.transform.position = transform.position; // Set to the same location as parent return(bloopObj); } else { return(null); } }