- Home /
OnTriggerEnter gives me error?
I have this script. It gives me error before running. First script, then 1 error/1 warning.
function OnTriggerEnter (obj : Collider)
{
if (obj.tag=="good")
{
Debug.Log("this is a friend of mine! – your energy has increased");
}
if (obj.tag=="good2")
{
Debug.Log("this is a friend of mine! – your energy has increased");
}
if (obj.tag=="bad")
{
Debug.Log("this is an enemy – you lost points");
}
if (obj.tag=="bad2")
{
Debug.Log("this is an enemy – you lost points");
}
}
ERROR Script error: OnTriggerEnter This message parameter has to be of type: Collider The message will be ignored.
WARNING Script 'Collider' has the same name as built-in Unity component. AddComponent and GetComponent will not work with this script.
Answer by drizztmainsword · Feb 17, 2013 at 09:17 PM
It looks like the name of the script you're using is "Collider.js", yes? You're going to need to change the name of the script.
What's going on is that because your script is called "Collider", it overrides the Collider type used in OnTriggerEnter. The function thinks that you're using your script as an argument, rather than a standard Unity Collider.
I would like to dedicate my university degree to Taylor Hadden, for helping me stay alive during the process.
Answer by Starkid225 · Feb 17, 2013 at 09:18 PM
According to the warning you have named your script 'Collider' which sometimes has a big effect on the functionality of some of the built in Unity functions. I would advise changing the name of that script and see if that fixes the problems.
Yea that was the problem... I changed it to "potato.js" and it worked flawlessly.
Your answer
Follow this Question
Related Questions
Detect when a trigger has entered a collider 1 Answer
Colliding two GameObjects 1 Answer
On Trigger Enter, Collide with object, specific collision 1 Answer
Trigger Spawning? 1 Answer
Keep doing something while colliding 1 Answer