public void Update() { // If guard can see player, save their location if (sm.SeePlayer(viewDistance)) { this.lastSeen = GameObject.Find("Player").transform.position; if (sm.SeePlayer(attackDistance)) { sm._state = GuardAI.State.StateShoot; } else { sm.agent.SetDestination(lastSeen); } } else { if (sm.SimilarVector3(sm.transform.position, lastSeen)) { sm._state = GuardAI.State.StateScan; } else { sm.agent.SetDestination(lastSeen); } } }
public void Update() { sm.agent.isStopped = true; if (sm.SeePlayer(attackDistance)) { GameObject bullet = Resources.Load <GameObject>(bulletPrefab); Instantiate(bullet, gunPoint.transform.position, gunPoint.transform.rotation); } else { sm._state = GuardAI.State.StateHunt; } sm.agent.isStopped = false; }
public bool DoScan() { // return true if find player in radius, else false // move player while scanning, so that if true, will be facing player when back to hunt // maybe also force set Hunt's lastSeen for (int i = 0; i < numRays; i++) { if (sm.SeePlayer(attackDistance)) { sm.hunt.lastSeen = GameObject.Find("Player").transform.position; return(true); } parent.transform.Rotate(0, turnDegrees, 0); } return(false); }
public void Update() { // If at pointA/B, reverse direction to the other if (sm.SimilarVector3(sm.transform.position, pointA)) { this.toA = false; } if (sm.SimilarVector3(sm.transform.position, pointB)) { this.toA = true; } // If guard can see player, change to StateHunt if (sm.SeePlayer(viewDistance)) { sm._state = GuardAI.State.StateHunt; } // Move to pointA if toA else pointB sm.agent.SetDestination(toA ? pointA : pointB); }