Colliding doesnt work
I am makign a fps game so i wanted to create explosive barrels. I have a collider which hast the tag is trigger active and a collider ( a bit smaller than the other) which hasnt this active ... here is my code ...
using UnityEngine; using System.Collections;
public class ExplosionScript : MonoBehaviour { public GameObject Barrel; public GameObject Explosion; // Use this for initialization void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter(Collider col)
{
if (col.tag == "Bullet")
{
Explosion.active = true;
Destroy(Barrel);
}
}
}
Unfortuneatly this isnt working ... pls help XD
Answer by softrare · Jan 30, 2016 at 04:56 PM
I always use OnCollisionEnter http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnCollisionEnter.html
Make sure all game objects involved in the collision have Colliders attached. At least 1 of them needs a non-kinematic rigidbody attached.
And just because you are new let me explain:
To make sure OnCollisionEnter is executed put in there a print("Boom!") so that you know that if not everything you want is happening (because of other possible coding mistakes) that still my advice was correct.
Please try it out and mark this answer as accepted if it worked.
Finally it worked ... if you have the same problem try : void OnCollisionenter (Collision other)
Glad it worked ;) I converted your answer to a comment if you don't $$anonymous$$d.
Your answer
Follow this Question
Related Questions
i have a model with capsule collider on it and when i shoot it want to dead but it not working 0 Answers
Get Random transform point inside collider 0 Answers
Instantiate is not working in unity 5.6.4f1 0 Answers
Changing depth of a SphereCollider without changing its size 2 Answers
Collider not turning into trigger when painted to a scene 1 Answer