I would like to create an indefinite amount of GameObjects (Spheres). During the game, certain actions will create a new sphere. To keep track of the spheres I would like to make a list since using arrays requires me to know how many spheres there are going to be.
Using the following script, I am able to create the spheres and add them to a list. If I try to change the position of a certain GameObject on the list (using Listname[2].transform.position.set(x,y,z) absolutely nothing happens. How can I change the properties of a certrain GameObject in a list?
Example:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Player : MonoBehaviour {
public GameObject playerSeg;
public int segNum, p = 1;
public Vector3 pos = new Vector3(1,1,1);
private Quaternion test;
public List<GameObject> SegList;
void Start () {
SegList = new List<GameObject>();
CreateSegment();
}
void Update () {
SegList [1].transform.position.Set(1,3,1);
}
void CreateSegment()
{
SegList.Add (Instantiate (playerSeg,pos,test));
}
}