Guest User

Enemy code source

a guest
Apr 25th, 2026
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.AI;
  3.  
  4. public class EnemyMovement : MonoBehaviour
  5. {
  6. // Reference to the player's transform.
  7. public Transform player;
  8.  
  9. // Reference to the NavMeshAgent component for pathfinding.
  10. private NavMeshAgent navMeshAgent;
  11.  
  12. // Start is called before the first frame update.
  13. void Start()
  14. {
  15. // Get and store the NavMeshAgent component attached to this object.
  16. navMeshAgent = GetComponent<NavMeshAgent>();
  17. }
  18.  
  19. // Update is called once per frame.
  20. void Update()
  21. {
  22. // If there's a reference to the player...
  23. if (player != null)
  24. {
  25. // Set the enemy's destination to the player's current position.
  26. navMeshAgent.SetDestination(player.position);
  27. }
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment