Cycle through targets.

Well, I have a newbie problem here.

I have my character looking at a fixed enemy (enemy1; there are 3 enemies in the scene) and I want to press a key to look at the next enemy. Basicly, I want to cycle through them but I have a problem. I have absolutely no idea how to do it. I know it probably has to do with arrays but the docs and “tutorials” all seem to be aimed at people with previous experience, not at newbies.
So, not only I need help with this specific thing, I also need to know where to find docs aimed at total newbies with no experience in this.

This is the part of my code dealing with targeting and “orbiting” the enemies.

var target : Transform;
var speed = 5.0;

function Update () {
transform.LookAt(target);
transform.eulerAngles.x=0;
transform.eulerAngles.z=0;
var x = Input.GetAxis("Horizontal") * Time.deltaTime * speed;
var z = Input.GetAxis("Vertical") * Time.deltaTime * speed;
transform.Translate(x, 0, z);
}

I’m not sure of the exact syntax as I use C# myself. But, you should change target to an array and assign via the inspector / find in scene all 3 enemies.

You would then have an int denoting which was the current enemy.

You would access target using this int and when pressing left and right increase and decrease the int, making sure it does not go below 0 or above the number or enemies in the array.

I believe simply changing the type of target to Transform will make it an array and if it is public and serialised to the inspector you can define its size there and drop on each enemy.

Thanks for the quick answer. Turning the Transform into an array worked perfectly but now it’s causing a problem I didn’t have before. With my previous code, my character would be constantly focusing on a fixed enemy. I could move around all I wanted and it would still be looking at the enemy. Basicly, I would be “orbiting” the enemy. Now that doesn’t happen anymore.
I have 3 enemies and when I press the “nexttarget” key, it looks at the next target and thats good but it doesn’t look at it all the time. When I switch target, it looks at the next target but it stops looking at it as soon as I start moving. How can I make it so that it keeps looking at the target even after I start moving around?
This is my current code:

var target : Transform[];
var speed = 5.0;
var targetnumber : int;





function Update () {

transform.eulerAngles.x=0;
transform.eulerAngles.z=0;
var x = Input.GetAxis("Horizontal") * Time.deltaTime * speed;
var z = Input.GetAxis("Vertical") * Time.deltaTime * speed;
transform.Translate(x, 0, z);



if (Input.GetButtonDown ("nexttarget")) {
targetnumber++;

if (targetnumber > 2) targetnumber = 0;

if (targetnumber == 0) {
transform.LookAt(target[0]);
}

if (targetnumber == 1) {
transform.LookAt(target[1]);

}

if (targetnumber == 2) {
transform.LookAt(target[2]);

}

}


}