Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

Is there any way I could make the enemy chase the player when detected if I already have this script?

$
0
0
I have this script: public class RandomMovement : MonoBehaviour { public NavMeshAgent agent; public float range; public Transform centrePoint; void Start() { agent = GetComponent(); } void Update() { if(agent.remainingDistance <= agent.stoppingDistance) { Vector3 point; if (RandomPoint(centrePoint.position, range, out point)) { Debug.DrawRay(point, Vector3.up, Color.blue, 1.0f); agent.SetDestination(point); } } } bool RandomPoint(Vector3 center, float range, out Vector3 result) { Vector3 randomPoint = center + Random.insideUnitSphere * range; NavMeshHit hit; if (NavMesh.SamplePosition(randomPoint, out hit, 1.0f, NavMesh.AllAreas)) { result = hit.position; return true; } result = Vector3.zero; return false; } } And I want to add a bool thats a *chase* and if it is false then that thing happens but if its true, then the destination is set as the player. I tried a few ways, but they all break the code up. Is it possible, or do I have to use another script with it already?

Viewing all articles
Browse latest Browse all 1488

Trending Articles