OnCollisionEnter doesn't work !
Hello ! I searched on Google but I didn't find my problem's solution. I'm creating a game, I've got a sphere, and that sphere (controlled by a joystick because it's a mobile game) has to move on a road and doesn't touch the oaks which are around the road. I did a script called "Collision" : using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Collision : MonoBehaviour
{
void OnCollisionEnter(Collision col)
{
if(col.gameObject.tag == "Oak")
{
Destroy(gameObject);
}
}
}
This script is made in order to destroy the sphere when it touches the oak. The oak is tagged "Oak". My oaks and my sphere have got a "RigidBody" (not 2D, this is a 3D game). That "RigidBody" hasn't got "Is Kinematic" checked.
I tried to change Destroy(gameObject);
by Debug.Log("Non!")
but this text doesn't appear in my console. I hope that I gave you enough details to find out what's my problem and where's it ! Sorry if my English isn't good, I am out of English speakers' countries. :D
Answer by TUTOCF · Feb 14, 2017 at 08:40 PM
I succeeded !!! The Sphere Collider doesn't work ! You've to use BOX COLLIDER ! I don't know why, but now it works.
Answer by HenryStrattonFW · Feb 14, 2017 at 07:57 PM
Your error may likely be because Unity does not recognise the method since you have named your own class "Collision" which will conflict with the existing "Collision" type. So unity doesn't recognise your method as its special method to call since it does not match the parameter requirements.
Rename your script to something else (and avoid using existing names in future as it's never a safe thing to do unless using namespaces). And see if that works.
That still doesn't work. I renamed it as "DestructeurObjects". Do you want to see something else in my settings ?
Your answer
Follow this Question
Related Questions
Unity 2D sorting item by color 0 Answers
Selective Collision Detection 2 Answers
My collision is not detecting 1 Answer
Best way to do Collision detection when you have multiple enemies/allies around you 0 Answers
2D: Destroy object with dynamic collider after exiting object with static collider 1 Answer