What's wrong with my AI script.

I have my script here but I don’t know how to fix the error.
/Scripts/AI.cs(37,35): error CS1501: No overload for method LookAt' takes 3’ arguments

using UnityEngine;
using System.Collections;

public class AI : MonoBehaviour {
	public int health = 100;
	public Transform target;
	public bool foundTarget = false;
	public int movespeed;
	public int rotateSpeed;
	private bool takeDamage = false;
	public Transform myTransform;



	// Use this for initialization
	void Start () {
		takeDamage = false;
		myTransform = transform;
		target = GameObject.FindWithTag("Player").transform;
	
	}
	
	// Update is called once per frame
	void Update () {

		if(takeDamage == true)
		{
			health -= 10;
		}
		if(health == 0)
		{
			gameObject.SetActive(false);
			takeDamage = false;
		}
		if(foundTarget && health > 0)
		{
			transform.LookAt(target.position.x, transform.position.y, target.position.z);
			myTransform.Translate(Vector3.forward * movespeed * Time.deltaTime);
		}


	
	}

	void OnTriggerEnter(Collider other)
	{
		if(other.gameObject.tag == "Bullet")
		{
			takeDamage = true;
		}

		if(other.gameObject.tag == "Player")
		{
			foundTarget = true;
		}
	}

	void OnTriggerStay(Collider other)
	{
		if(other.gameObject.tag == "Bullet")
		{
			takeDamage = true;
		}
	}

	void OnTriggerExit(Collider other)
	{
		if(other.gameObject.tag == "Bullet")
		{
			takeDamage = false;
		}
	}
}

Assets/Jason’s Stuff/Scripts/AI.cs(37,35): error CS1501: No overload for method LookAt' takes 3’ arguments

Hey.

Your problem comes up because there is no method for LookAt that takes 3 arguments, which you are feeding it in the form of an x, y and z, coordinate. You need these to be given as one argument, i.e. a vector 3.

You can solve this in 2 ways I can think of. If you are trying to make it look at a GameObject (a target), save that target in a GameObject variable and simply write

transform.LookAt(target);

You might even be able to solve it with just this

transform.LookAt(target.gameObject);

Otherwise, you can just go ahead and write, which I think should solve it too. ´

transform.LookAt(vector3(target.position.x, target.position.y, target.position.z);

Good luck and have fun making games

LookAt takes a whole Vector3… not the pieces of one.

You are not using the “LookAt” reference as intended, seeing it only takes 2 arguments.

So replace
“transform.LookAt(target.position.x, transform.position.y, target.position.z);”

With:

“transform.LookAt(target);”

If you absolutely need to have the y of the current gameobject, you can simply do this:

if(foundTarget && health > 0)
       {
target.position.y = transform.position.y; 
transform.LookAt(target);
myTransform.Translate(Vector3.forward * movespeed * Time.deltaTime);
       }