Yet another onTriggerEnter()
Yet another onTriggerEnter()
I am aware that many have already posted their problems with this command. I have tried all the differen recommendations but I am still unable to get the onTriggerEnter method to work for me.
I am following a set of tutorials and the objective is to create sort of a minigame in which you, using the FirstPersonCharacter controller collect coins.
The FirstPersonCharacter has a RigifBody attached to it, Gravity is applied and it is Kinematic, the "Player" tag is applied to the object.
The coin has a a rotation script (one of the default assets), a mesh collider with the Is Trigger checkbox and the collection script. The "Coin" tag is applied to this game object and it is static.
public class collect : MonoBehaviour
{
private void onTriggerEnter(Collider c0ol)
{
Debug.Log("Registered Trigger");
}
private void onCollisionEnter(Collision col)
{
Debug.Log("Registered Collision");
}
}
I also placed a Debug.Log() in each method to ensure that I get something returned in case a Collision or a Trigger is activated.
I run through the coins and nothing is triggered. I have tried putting a rigid body component into the coin as well, but nothing gets triggered. I am well aware that Static Trigger Collider (Coin) should sent a trigger with a Rigid Body (player) accoding to the table at the bottom of this document.
Is there anything I am missing?
Thank you in advance for your help.
onTriggerEnter
O
OnTriggerEnter
OnCollisionEnter
1 Answer
1
You need to use a capital O
as in OnCollisionEnter
and OnTriggerEnter
.
O
OnCollisionEnter
OnTriggerEnter
C# is case sensitive, so foo
is not the same as Foo
or fOo
.
foo
Foo
fOo
This should work:
public class Collect : MonoBehaviour
{
private void OnTriggerEnter(Collider c0ol)
{
Debug.Log("Registered Trigger");
}
private void OnCollisionEnter(Collision col)
{
Debug.Log("Registered Collision");
}
}
foo is not the same as Foo or fOo
or, strangely enough, fоо
– Draco18s
Jun 30 at 21:22
foo is not the same as Foo or fOo
fоо
Indeed! How could I have missed such an important detail! Problem solved, thank you sensei.
– AMP
Jun 30 at 21:46
Haha, well Windows and Macs aren't case sensitive so we tend to get used to not thinking about that. You're welcome
– AustinWBryan
Jul 1 at 0:11
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
onTriggerEnter
needs to start with a capitalO
->OnTriggerEnter
(and the same is true forOnCollisionEnter
)– UnholySheep
Jun 30 at 19:12