Hi i want destroy spawned obejcts in other script. Script below spawn thia obejcst.
`public class spawner : MonoBehaviour
{
[SerializeField] GameObject items;
[SerializeField] float spawnspeed = 0.5f;
[SerializeField] float minrange;
[SerializeField] float maxrange;
void Start()
{
StartCoroutine(itemspawner());
}
IEnumerator itemspawner()
{
while(true)
{
var wanted = Random.Range(minrange, maxrange);
var position = new Vector3(wanted, transform.position.y);
GameObject gameObject= Instantiate(items[Random.Range(0, items.Length)],position, Quaternion.identity);
yield return new WaitForSeconds(spawnspeed);
Destroy(gameObject, 5f);
}
}`
In other script i check if object colide with my crosshair and in that script i want to destroy spawned objects. But i want spawn couple of objects with function i posted. Some of this objects when destroy give me some point other take a life. I dont know how to do it. This is my first project.