Hi, I have a script where I randomly spawn a given array of objects at a random time between 2 values. What I have been stuck on for the past hour is trying to get the transform component of the object I just instantiated, so I can reset the position after a certain time. Thus, making a pool for all my objects.
The code is as follows:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class BugSpawn : MonoBehaviour
{
public GameObject[] objlist;
public float spawnmin = 1f;
public float spawnmax = 2f;
public bool firsttime;
void Start ()
{
firsttime = true;
Spawn ();
}
void Spawn ()
{
if (firsttime == false) {
Instantiate (objlist [Random.Range (0, objlist.GetLength (0))], transform.position, Quaternion.identity);
}
Invoke ("Spawn", Random.Range (spawnmin, spawnmax));
firsttime = false;
}
}
Thanks! any help is greatly appreciated