- Home /
Duplicate Question
How to create an array of Transforms
I have a game object at each corner of my plane. I have an AI script that will send enemy game objects to my player object. When a collision happens I have the enemy stop and then temporarily go towards a corner. But I want the enemy to randomly go to 1 of the four corners.
I know I need to do this by hold the corner game objects in an array and then referencing the transform of one of those objects. However I am very rusty with arrays. Can you give me an example of how I can create an array of gameobject transforms and how I can reference them?
var corner1 : Transform;
var corner2 : Transform;
var corner3 : Transform;
var corner4 : Transform;
var cornerOne : GameObject;
var cornerTwo : GameObject;
var cornerThree : GameObject;
var cornerFour : GameObject;
var targetTrans : Transform;
function Start()
{
cornerOne= GameObject.FindWithTag ("corner1");
cornerTwo= GameObject.FindWithTag ("corner2");
cornerThree= GameObject.FindWithTag ("corner3");
cornerFour= GameObject.FindWithTag ("corner4");
corner1 = cornerOne.transform;
corner2 = cornerTwo.transform;
corner3 = cornerThree.transform;
corner4 = cornerFour.transform;
}
function Update ()
{
targetTrans = this.transform;
}
Answer by Benproductions1 · May 28, 2013 at 12:09 AM
DUPLICATE QUESTION!!
http://answers.unity3d.com/questions/238239/array-of-transforms.html
http://answers.unity3d.com/questions/10986/transform-array-in-javascript.html
http://answers.unity3d.com/questions/252745/storing-transforms-from-objects-in-array.html
http://answers.unity3d.com/questions/14762/array-of-gameobjects.html
http://answers.unity3d.com/questions/331603/array-of-transforms-with-variable.html
The wonders that a google search can do for you!!
Your welcome!
Benproductions1
Funny how a few years down the line a Google search brings me to this post for me to be diverted to a bunch of other related posts.