// Start is called before the first frame update void Start() { movementCapability = GetComponent <MovementCapability>(); edible = GetComponent <EdibleState>(); eater = GetComponent <EatOnCollide>(); playerController = GetComponent <PlayerController>(); }
public void Start() { Age = 0.0f; energyState = GetComponent <EnergyState>(); movementCapability = GetComponent <MovementCapability>(); eater = GetComponent <EatOnCollide>(); edible = GetComponent <EdibleState>(); massMove = GetComponent <MovementBasedOnMass>(); ai = GetComponent <FishAI>(); if (ColorTarget != null) { mesh = ColorTarget.GetComponent <MeshRenderer>(); } }
private void NextCommand() { playerController = GetComponent <PlayerController>(); EdibleState food = null; EatOnCollide predator = null; float foodDistance = 1.0e9f, predatorDistance = 1.0e9f; Vector3 position = transform.localPosition; foreach (var otherEdible in FindObjectsOfType <EdibleState>()) { if (otherEdible.FoodClass == eater.FoodClass) { // found food :) var distance = Vector3.Distance(position, otherEdible.transform.localPosition); if (distance < foodDistance) { food = otherEdible; foodDistance = distance; } } } if (edible != null) { foreach (var otherEater in FindObjectsOfType <EatOnCollide>()) { if (otherEater.FoodClass == edible.FoodClass) { // found predator :( var distance = Vector3.Distance(position, otherEater.transform.localPosition); if (distance < predatorDistance) { predator = otherEater; predatorDistance = distance; } } } } if (predatorDistance < foodDistance) { nextCommandX = position.x + (position.x - predator.transform.localPosition.x) * 10.0f; nextCommandY = position.y + (position.y - predator.transform.localPosition.y) * 10.0f; commandTimeout = predatorDistance * .5f; } else if (food != null) { nextCommandX = position.x + (food.transform.localPosition.x - position.x) * 4.0f; nextCommandY = position.y + (food.transform.localPosition.y - position.y) * 4.0f; commandTimeout = foodDistance * .5f; } else { float size = 16.0f; nextCommandX = position.x + UnityEngine.Random.Range(-size, size); nextCommandY = position.y + UnityEngine.Random.Range(-size, size); commandTimeout = UnityEngine.Random.Range(1.0f, 2.0f); } commandAlertness = Mathf.Clamp01(3.0f - Mathf.Max(predatorDistance / 5.0f, foodDistance / 5.0f)); commandTimeout *= UnityEngine.Random.Range(.1f, .6f); commandTimeout = Mathf.Clamp(commandTimeout, .1f, 4.0f); }