public void EndPatrolling(RatBrain.RatState state) { stateRef = state; if (hasCoroutineStarted) { canPatrol = false; hasCoroutineStarted = false; StopCoroutine(Patrol()); } }
public void BeginPatrolling(RatBrain.RatState state) { if (!hasCoroutineStarted) { canPatrol = true; hasCoroutineStarted = true; stateRef = state; StartCoroutine(Patrol()); } }
public void EndChasing(RatBrain.RatState state) { stateRef = state; if (hasCoroutineStarted) { canChase = false; hasCoroutineStarted = false; this.target = null; StopCoroutine(Chase()); } }
// 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; } }
// 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); } }
// 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; } } }
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()); } }
public void SetStateRef(RatBrain.RatState state) { stateRef = state; }