I'm not exactly sure what I'm doing wrong here. The results I want is clone the game object set it active then delete game Object clone. But instead, It's it deleting the game Object base which is stopping from happening again.
if (AttackChoice == 2)
{
MaxedOut();
gameObject.GetComponentInChildren<Renderer>().material.color = Color.white;
var clone = Instantiate(Pt, portalSpawn.position, Quaternion.identity);
_clones.Add(clone);
clone.transform.parent = null;
Pt.gameObject.SetActive(true);
yield return new WaitForSeconds(10);
Destroy(clone);
gameObject.GetComponentInChildren<Renderer>().material.color = originalColor;
}
CodePudding user response:
You say
The results I want is clone the game object set it active then delete game Object clone
and you clone the GameObject Pt
:
var clone = Instantiate(Pt, portalSpawn.position, Quaternion.identity);
but then you don't set it active, you set Pt
active instead:
Pt.gameObject.SetActive(true);
and then later you destroy the clone:
Destroy(clone);
Your question is poorly worded so I can't tell what exactly the issue is here. It sounds like you think you're deleting Pt
, the source for the clone instantiation, which is preventing you from re-running the instantiation code (because it's null), but you are NOT destroying Pt
in the snippet you've provided.
You are adding the clone
to a _clones
list, which makes me think you're doing something else, and I'm wondering if the scripts that are living on the Pt
GameObject are somehow triggering the object to self-destruct. In that case, just active the correct object by:
clone.gameObject.SetActive(true);
instead of activating the Pt
object.