- Home /
Question by
tiffanysun · Oct 08, 2016 at 07:33 AM ·
triggercollidersshooting
How to make Object disappear OnTriggerEnter? For prefab shooting
hi, this is my code for making the hotdog hit the enemyBear to make it disappear.
I can get the shooter to work, but it doesn't work when the object hits the enemyBear.
using UnityEngine; using System.Collections;
public class HotdogCollision : MonoBehaviour {
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "enemyBear")
{
Debug.Log (other.gameObject.name);
Destroy(other.gameObject,3f);
}
}
}
Comment
$$anonymous$$ake sure one of the objects has a rigidbody (a kinematic rigidbody works too).
your trigger is needing on triggerenter 2D
Check unitys script references they have exact codes you need the 2d on trigger
Answer by aditya · Oct 08, 2016 at 07:38 AM
Two possible reasons
If your game is a 2D game then this OnTriggerEnter should be OnTriggerEnter2D
Else, your tag is not matching or your enemy bear does'nt have any tag
Your answer