- Home /
destroying cloned prefab not working as intended
Hi, I am trying to destroy a cloned prefab with on trigger stay like this below
public void OnTriggerStay(Collider other)
{
if (other.gameObject.name == "Prop_Wood_1(Clone)" && Input.GetKey(KeyCode.C) &&
gameObject.name == "Male White" && onlyPickUpLogWhenNotRecoveringBreath == false)
{
StartCoroutine("waitBeforeDestroyingLogsOnPickUp");
}
}
and if there is more than one cloned object it always destroys the first instantiated prefab even if I am on the second or third etc.
thank you in advance, I hope you understand what I'm trying to explain.
I did not got your question still i think the problem is other.gameObject.name == "Prop_Wood_1(Clone)" do use gameobject.tag not name in case of clones and also copy tag name from editor spelling mistake is very common problem :)
Os$$anonymous$$d of using .name, you can youse .name.Contains(".....")
Your answer
Follow this Question
Related Questions
Game object is destroyed 1 Answer
Prevent destruction of an object's child 1 Answer
Collision Detection not working? 1 Answer
Spawned objects randomly not destroyed 1 Answer
Deleting objects from list sequence 1 Answer