/** * Called when the fish is enabled */ private void OnEnable() { // get refs rigid = GetComponent <Rigidbody>(); fishAppearance = GetComponentInChildren <FishAppearance>(); // set up initial energy currentEnergy = startingEnergy; }
public void MakeSons(List <FishAppearance> prefabs) { foreach (FishAppearance prefab in prefabs) { FishAppearance evolution = GameObject.Instantiate(prefab, transform); evolution.LinkAndSleep(god); evolution.GetComponent <Transform>().position = new Vector3(0f, 0f, 0f); sons.Add(evolution); } // For some reason, it only works on the second element in the list? // If you pass in 0 or FishGod.level (also 0), the sprites don't update // when the fish gets hungry. // Also, the order of the sprites in the list is the reverse of what it is // in the Inspector. sons[1].SetIsSleeping(false); // Wake current appearance }
/** * Called when the fish is enabled */ private void OnEnable() { // Get References rigid = GetComponent <Rigidbody>(); fishAppearance = GetComponentInChildren <FishAppearance>(); school = FindObjectOfType <FishSchool>(); // Craft the path this fish will follow // While the fish is waiting to have its school assigned by the Fish School script, we wait destination = school.initialDestinations[Random.Range(0, 5)]; Vector3 lookPosition = destination.destinationPosition - transform.position; destinationDirection = Quaternion.LookRotation(lookPosition); //destinationDistance = Vector3.Distance(transform.position, destination.destinationPosition); //travelTime = destinationDistance / swimSpeed; path.Add(destination); Destination currentNode = destination; while (craftingPath) { Destination newNode = currentNode.destinations[Random.Range(0, 5)]; if (newNode.finalDestination == true) { path.Add(newNode); craftingPath = false; } else { path.Add(newNode); currentNode = newNode; } } // Set up initial energy currentEnergy = startingEnergy; }