Ejemplo n.º 1
0
 public void EndPatrolling(RatBrain.RatState state)
 {
     stateRef = state;
     if (hasCoroutineStarted)
     {
         canPatrol           = false;
         hasCoroutineStarted = false;
         StopCoroutine(Patrol());
     }
 }
Ejemplo n.º 2
0
 public void BeginPatrolling(RatBrain.RatState state)
 {
     if (!hasCoroutineStarted)
     {
         canPatrol           = true;
         hasCoroutineStarted = true;
         stateRef            = state;
         StartCoroutine(Patrol());
     }
 }
Ejemplo n.º 3
0
 public void EndChasing(RatBrain.RatState state)
 {
     stateRef = state;
     if (hasCoroutineStarted)
     {
         canChase            = false;
         hasCoroutineStarted = false;
         this.target         = null;
         StopCoroutine(Chase());
     }
 }
Ejemplo n.º 4
0
 // Start is called before the first frame update
 void Start()
 {
     mtc = GetComponent <MoveToTargetComponent>();
     if (waypoints.Count > 0)
     {
         state           = RatBrain.RatState.PATROL;
         currentWaypoint = waypoints[currentIndex];
         mtc.BeginChasing(state, currentWaypoint);
     }
     else
     {
         state = RatBrain.RatState.UNDECIDED;
     }
 }
Ejemplo n.º 5
0
 // Update is called once per frame
 void Update()
 {
     if (sensingComp.HasTargetToFollow())
     {
         state = RatBrain.RatState.CHASE;
         GameObject target = sensingComp.GetTarget();
         moveToTargetComp.BeginChasing(state, target);
     }
     else
     {
         state = RatBrain.RatState.PATROL;
         moveToTargetComp.EndChasing(state);
     }
 }
Ejemplo n.º 6
0
 // Update is called once per frame
 void Update()
 {
     if (waypoints.Count > 0)
     {
         Vector3 distance      = transform.position - mtc.target.transform.position;
         bool    isCloseEnough = distance.magnitude < mtc.stoppingDistance;
         if (isCloseEnough)
         {
             state = RatBrain.RatState.UNDECIDED;
             mtc.EndChasing(state);
             currentIndex    = (currentIndex + 1) % waypoints.Count;
             currentWaypoint = waypoints[currentIndex];
             mtc.BeginChasing(state, currentWaypoint);
             state = RatBrain.RatState.PATROL;
         }
     }
 }
Ejemplo n.º 7
0
    public void BeginChasing(RatBrain.RatState state, GameObject target)
    {
        stateRef = state;
        // change target if currentTarget is overwritten from SensingComponent
        if (this.target != null && this.target != target)
        {
            StopCoroutine(Chase());
            hasCoroutineStarted = false;
        }

        // if rat has not seen anyone yet, chase the first target it sees
        if (!hasCoroutineStarted)
        {
            canChase            = true;
            hasCoroutineStarted = true;
            this.target         = target;
            StartCoroutine(Chase());
        }
    }
Ejemplo n.º 8
0
 public void SetStateRef(RatBrain.RatState state)
 {
     stateRef = state;
 }