- Home /
Map GameObjects to Array of Positions
I have an array consisting of {x,y,z} coordinates. I would like to create a game object for each coordinate. I've been watching tutorials about importing and Instantiate but have not been able to move forward. My file type can be converted into any form necessary for import.
Have: array of 3-tuple coordinate. approximately 300 tuples.
Need: Scripting help to map a game object to each coordinate.
So what's the problem exactly? Loop over the array and pass the x,y,z coords to create the Vector3 transform.position at which Instantiate() creates the object. Post your code if you are stuck.
$$anonymous$$y problem is simply experience level. C# is brand new to me and I have been using Unity less than a week. I'll follows those tips and once I have something I'll post the code. Thanks @tanoshimi
Answer by IvovdMarel · Jun 16, 2014 at 09:24 PM
public GameObject myPrefab; // Set this variable in the inspector
private Vector3[] objectPositions = new Vector3 {
new Vector3(0,0,1),
new Vector3(0,1,1)
}; // or whatever your points in the array are
private void Awake () {
foreach (Vector3 objectPos in objectPositions) {
GameObject myObject = Instantiate (myPrefab) as GameObject;
myObject.transform.position = objectPos;
}
}
Something like that?
@Ivovdd$$anonymous$$arel .. This helped a huge amount. Thanks for taking the time to code it out.
@miles1618 - If this answer answered your question, please click on the checkmark next to the answer to close it out. Thanks.