Skip to content

Instantly share code, notes, and snippets.

@DarrenTsung
Last active December 2, 2017 16:40
Show Gist options
  • Save DarrenTsung/206a7f79173840cff84ea8a0960e8a68 to your computer and use it in GitHub Desktop.
Save DarrenTsung/206a7f79173840cff84ea8a0960e8a68 to your computer and use it in GitHub Desktop.
void BeOnTheLookout(float radius) {
Collider[] hitColliders = Physics.OverlapSphere(transform.position, radius);
int highestBounty = 0;
Collider mostWantedCriminal = null;
foreach (Collider criminal in hitColliders) {
var bounty = criminal.GetComponent<Bounty>();
if (bounty == null) {
continue;
}
if (highestBounty < bounty.wanted) {
highestBounty = bounty.wanted;
mostWantedCriminal = criminal;
}
}
if (mostWantedCriminal == null) {
return;
}
Pursuit(mostWantedCriminal.transform.position);
if (Vector3.Distance(transform.position, mostWantedCriminal.transform.position) < rangeToPunch) {
agent.isStopped = true;
anim.SetTrigger("Punch");
} else if (Vector3.Distance (transform.position, mostWantedCriminal.transform.position) > rangeToPunch) {
Pursuit(mostWantedCriminal.transform.position);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment