void Start () { rb = GetComponent<Rigidbody>(); navMeshAgent = GetComponent<NavMeshAgent>(); target = BunnyMoveTarget.RandomTarget; state = State.Evaluating; StartCoroutine (FSM ()); food = getClosest (GameObject.FindGameObjectsWithTag ("Fruit")); }
void generatePath(BunnyMoveTarget targt){ Vector3 destination; do { food = getClosest (GameObject.FindGameObjectsWithTag ("Fruit")); destination = getRandomPositionInNavMesh (); navMeshAgent.SetDestination (destination); //Debug.Log("NavMeshPathStatus: "+ navMeshAgent.path.status); } while(navMeshAgent.path.status != NavMeshPathStatus.PathComplete); }
IEnumerator Evaluating(){ if (hunger >= 10 * hungerBoundary) { Debug.Log("Me muero de hambre"); DestroyObject(this.gameObject); }else if(fatigue >= 10*fatigueBoundary){ Debug.Log("Me muero de fatiga"); DestroyObject(this.gameObject); }else if (hunger >= hungerBoundary) { Debug.Log ("Voy a buscar comida"); target = BunnyMoveTarget.FoodTarget; generatePath(target); state = State.Moving; }else if (fatigue >= fatigueBoundary) { Debug.Log ("Estoy cansado. " + fatigueBoundary); state = State.Resting; } else { Debug.Log("Me voy a dar un garbeo por ahí."); target = BunnyMoveTarget.RandomTarget; generatePath(target); state = State.Moving; } yield return null; }