Shooting Enemy AI with Patrol

Hi everyone I am doing a FPS game. I need a enemy ai, when enemy see the player he should shoot at him and start follow him and when the player is not there he should patrol. I am new to unity and c# so please put the script and animator controller of the enemy Pls!!! Thanks in advance :slight_smile:

If you are new to Unity and coding I would highly recommend you find some tutorials on the web. Though some may be glad to just drop some code for you, you will never learn that way and will find yourself back here for every problem you face. Along the lines of the old proverb “Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for life”.

Use collider to detect player collision detection with specific distance (Collider size “x,z” axis) and make sure is player detect then check raycast hit between player and enemy, is there any other object exist in between then dont shoot otherwise shoot.

Code to check is there player raycast or not:

if (Physics.Raycast(playerCamera.transform.position, playerCamera.transform.forward, out hit, 200))
{
     if (hit.transform.CompareTag("Player"))
     {
           Debug.LogError("Shoot player!!!");
     }else
     {
           Debug.LogError("Dont Shoot");
     }
 }