I Was wondering if anyone could help me with this;
So i have 8 cubes, which would possibly use a trigger, anyway.
I Have an object, and i want to spawn the object inside ONE OF THE CUBES, so it’s different every time, it could be cube 1, or 2 or 3 or 4 or 5, and so on. So it chooses one cube and spawns the object there.
Could anyone possibly help me out with how i would do this?
Once you have your array of GameObjects, use the randomised number from step 1 to select a specific GameObject and use that GameObject’s position as a the location for your initial object Object to spawn
YourCubeObjectType cubes = FindObjectsOfType(typeof(YourCubeObjectType)) as YourCubeObjectType;
Instantiate(YourSpawnObjectType, cubes[Random.Range(0, cubes.Length)].transform.position, Quaternion.identity)
Should do it (it’s almost the same in JS if that’s your preference). Of course, you can use Vector3.zero position for instantiation, and then you can add your spawned object as a child of one of the cubes if you wish for it to move with the parent cube like: