Why is this code giving me an error... lots of them

i dont get why this script is giving me a lot of errors its like right out of the reference material. i am thinking it has to do with the if and the on trigger, but i could be completely wrong any help?

   function Update () {
	
	if(gameObject.tag == "enemy")
		{
		function OnTriggerEnter(other : Collider)
		{
		transform.LookAt(gameObject);	
		}
		}
	
}

after i did the above code i looked around and found my errors… i think… but i am still having trouble any help?

function Update () {

var enemy = GameObject.FindWithTag("enemy");
var trigger = false;

OnTriggerEnter(enemy);

OnTriggerExit(enemy);

	if(trigger == true){

		transform.LookAt(enemy);
	}
}

function OnTriggerEnter(enemy : Collider){

	return trigger = true;
}

function OnTriggerExit(enemy : Collider){

	return trigger = false;
}

Something like the following (which hasn’t been compiled so expect a few typos):

static var doit = false;

function Update () {
	
	if(gameObject.tag == "enemy") {

   		doit = true;
	}
    else  {
    	doit = false;
	}
}

function OnTriggerEnter(other : Collider)
{
	if (doit) {
	    transform.LookAt(gameObject);
    }
}

Your code seems to do nothing since you’re trying to have the object to look at itself.

This is my best guess for what you want to do:

function OnTriggerEnter(other : Collider)
{
    if (other.tag == "enemy") // If I entered trigger of an enemy
    {
        transform.LookAt(other.transform); // Then I will look at that trigger
    }
}

In this solution there is no Update function at all.

Because the function OnTriggerEnter is an own function and must be outside of the Update function where you put it in by error