unity chose random gameobject and spawn it.

So I haven’t got a code for it yet but I have been struggling for a while trying to figure out how to spawn random gameobject out of about 10 at the location of a different gameobject of which the script is on. So every 5 seconds for example on of the gameobects will spawn on the gameobject with the script.

So you have object A that has a script that spawns another object (1 of 10 randomly) at A’s location. ? If that’s the case:

public Spawner : MonoBehaviour {
    [SerializeField] private GameObject[] objectsToSpawn;

    void Start()
    {
        Spawn();
    }

    public GameObject Spawn()
    {
        int index = objectsToSpawn.Length;
        if ( index > 0 )
        {
            index = Random.Range(0, index);
            return Instantiate ( objectsToSpawn[ index ] , transform.position, Quaternion.identity );
        }
        return null;
    }
}

If you want random rotation, you can change Quaternion.identity for something like Quaternion.Lerp( rotationA , rotationB, Random.Range(0f,1f) ); , or you can set it as Quaternion.identity and then rotate the instantiated object Random degrees.

Thanks man your scripts really helped and with a bit of tweaking I got it working :slight_smile: