- Home /
Instantiating objects at different locations
Hi, I have four 2D squares on the screen. When the player presses one of the squares, I want a ball to instantiate from the position of the square that was pressed. How should I go about doing this?
I have 2 game object arrays, a prefab and clone, and 1 vector2 array, and then a for loop that doesn't work.
Not sure how to fix it.
public GameObject[] beatBallPrefab; public GameObject[] beatBallArray; public Vector2[] newPositions;
beatBallArray = new GameObject[beatBallPrefab.Length];
for (int i = 0; i < beatBallPrefab.Length; i++)
{
newPositions = new Vector2[4];
beatBallArray[i] = Instantiate(beatBallPrefab[i],
newPositions[i], transform.rotation);
}
Thanks!
Your answer
Follow this Question
Related Questions
Make object move in a direction depending on where it spawns? (C#) 1 Answer
How to only instantiate objects once? 1 Answer
Spawn object at a random predeterminated(transform) position 1 Answer
How to save/load the Y-Coordinates of Instantiated Objects 1 Answer
Instantiate projectile at position of specific game object 1 Answer