Last active
December 2, 2017 16:40
-
-
Save DarrenTsung/206a7f79173840cff84ea8a0960e8a68 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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