After one game object gets set false or destroyed, make another game object go away.
I made this script but it appears to not be working: using System.Collections; using System.Collections.Generic; using UnityEngine;
public class InsrantiateSpike : MonoBehaviour { public GameObject tentacle; public GameObject self;
// Start is called before the first frame update
void Start()
{
Instantiate(tentacle);
}
void Update()
{
if (self.activeInHierarchy == false)
{
Destroy(tentacle);
}
}
}
Comment
Answer by goutham12 · Aug 27, 2019 at 04:04 AM
It won't work beacause it has two problems
script won't run if the object(script which is attatched) is deactivated.
you are destroying the refference object not the spawned object.
Here how you have to do
GameObject X;
void Start() {
X = Instantiate(tentacle);
}
void OnDisable(){
if(X != null){
Destroy(X);
}
}