Question by
Jojoba007 · Aug 19, 2017 at 03:38 PM ·
instantiatedestroyclone
Destroy the first instantiated clone after 4 have been instantiated
Hi all, I know it must be a simple, but I can't find the proper solution.
How would I destroy the first instantiated clone after 4 have been instantiated?
This is my code so far but doen't work (this script is connected to the instantiated objects):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class destroyPilar : MonoBehaviour {
GameObject[] oldPilar;
// Use this for initialization
void Awake ()
{
oldPilar = GameObject.FindGameObjectsWithTag ("Platform");
if (oldPilar.Count >= 3) {
Destroy(oldPilar[0]);
}
}
}
Comment
Best Answer
Answer by Jojoba007 · Aug 19, 2017 at 03:53 PM
Never mind, got it. How easy ;-)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class destroyPilar : MonoBehaviour {
GameObject[] oldPilar;
// Use this for initialization
void Awake ()
{
oldPilar = GameObject.FindGameObjectsWithTag ("Platform");
if (oldPilar.Length > 3) {
Destroy(oldPilar[0]);
}
}
}