I am trying to do a instantiate a game object to the child of another. It works, but every single gameobject I instantiate is in the same spot, when I want them to be in relation to their parent gameobject. The parent in my code would be “prefab” and the child that I am trying to make is “EmptyRayGameObject”
drones = new List<GameObject>();
for (int i = 0; i < droneCount; i++)
{
droneTemp = (GameObject) GameObject.Instantiate(prefab);
EmptyRayGameObject = (GameObject) GameObject.Instantiate (ePrefab);
I have tried this, and it kind of works, but still all the gameobjects are in the same spot, as opposed to being like 10 units in front of their parent gameobject.
EmptyRayGameObject.transform.parent = droneTemp.transform;
Answers I’ve tried (not succeeded)
drones = new List<GameObject>();
for (int i = 0; i < droneCount; i++)
{
droneTemp = (GameObject) GameObject.Instantiate(prefab);
EmptyRayGameObject = (GameObject) GameObject.Instantiate(ePrefab);
EmptyRayGameObject.transform.parent = droneTemp.transform;
EmptyRayGameObject.transform.localPosition = new Vector3(0.5f,0.5f,0.5f);