I'm creating gameObject instances of a prefab in my scene. Whats Im trying to do is add the position as well as the gameobject itself to a list in order for me to access each game object and check its current position. I'm going to have probably more than 30 game objects moving in my scene. How can i do that in CSharp?
Lists require using System.Collections.Generic at the top of the script.
[SerializeField] Transform prefab;
List<Transform> prefabTransforms;
void Start () {
prefabTransforms = new List<Transform>();
// I don't how you're actually instantiating.
prefabTransforms.Add(Instantiate(prefab, Vector3.right, Quaternion.identity) as Transform);
prefabTransforms.Add(Instantiate(prefab, Vector3.up, Quaternion.identity) as Transform);
// just an example of something you can access after you populate the List
prefabTransforms.ForEach(prefabTransform => Debug.Log(prefabTransform.position));
}
import System.Collections.Generic; //javascript uses (import) C# uses (using)
var prefabTransforms : List.<Transform>; //dont forget the (.) period right after List
And replace the void Start() with function Start()