Hi there!
I managed myself to find some resources around the internet and at the end this script came out! :3
Sadly, now i have the problem that i do not know how to avoid the enemy “Detecting” the player trough, for example a cube or a wall.
Any ideas? =)


Also, if for whatever reason the user getyour411 happens to be reading this i’ll be glad for you to know that i never asked for a Script!! ¬¬ If so, i wouldn’t bothered mattyman174 to explain me “HOW” not give me a way of avoid detection through walls.

using UnityEngine;
using System.Collections;

public class EnemyAI : MonoBehaviour {
	public Transform player;
	float distancefrom_player;
	public float look_range = 20.0f;
	public float agro_range= 10.0f;
	public float move_speed= 5.0f;
	public float damping = 6.0f;
	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () 
	{
		distancefrom_player = Vector3.Distance (player.position, transform.position);
	}
	void FixedUpdate()
	{
		if (distancefrom_player < look_range ) 
		{
			transform.LookAt(player);
		}
		
		if (distancefrom_player < agro_range) 
			
		{
			attack();
		}
	}
	
	void lookAt()
	{
		Quaternion rotation = Quaternion.LookRotation (player.position - transform.position);
		transform.rotation = Quaternion.Slerp (transform.rotation, rotation, Time.deltaTime * damping);
	}
	
	void attack()
	{
		transform.Translate (Vector3.forward * move_speed * Time.deltaTime);
	}
}

Use a raycast from the enemy to the player. If the raycast hit’s something other then the player or nothing; the player is out of sight. :slight_smile:

Just make sure the raycast doesn’t collide with the enemy itself :wink: