How do I get OnTriggerEnter to work?
So I'm new to Unity but I've been stuck on a problem for more than 6 hours. The problem is that I can't get Unity to print something in the console. when I enter:
void OntriggerEnter(Collider Player) { Debug.Log("You lose?");
}
to a roller game created by:https://www.youtube.com/watch?v=VqqefF1M1SQ&t=3331s (55:31) I have is Trigger selected and I have a Rigid body on my cube and a sphere collider(named Player with "Player" tag. I also have a cylinder collider that has the isTrigger . This is my first question so I don't know how to post the code for it/pictures but if anyone has tips/videos on how to solve this problem that would help thanks.(If I don't respond it is because I went to bed and I will Answer tomorrow.)
Answer by AmandaO · Oct 14, 2020 at 05:28 PM
@Loyalgamer45 I'm new as well but my teacher recently taught us this. Do an if statement, I believe this should work.
It checks for if the player tag has entered the trigger. If so, it will print the statement to the console.
private void OnTriggerEnter(Collider Player)
{
if (Player.transform.CompareTag("Player"))
{
Debug.Log("You Lose?")
}
}