Question by
edgartip2003 · Apr 05, 2019 at 09:50 PM ·
gameobjecttransformarrayspawning-enemiesspawn points
How to get the initial position of all gameobjects in an array unity
Hello! I have been trying to get the initial positions of all my gameobjects in an array, so that I can use that information to make these gameobjects return to this position after an event occurs ( enemy spawn point). Could you help me? Or is there an easier way? I have been searching but nothing seemed to apply.
Comment
Could you provide a code example how you want to spawn your enemy.
Best Answer
Answer by Chris333 · Apr 06, 2019 at 11:19 AM
You could save the positions in the start method.
using UnityEngine;
public class Test : MonoBehaviour {
public GameObject[] enemies;
public Vector3[] enemiesInitialPosition { get; set; }
// Use this for initialization
void Start () {
enemiesInitialPosition = new Vector3[enemies.Length];
for(int i = 0; i < enemies.Length; i++)
{
enemiesInitialPosition[i] = enemies[i].transform.position;
}
}
}