when I enter the square we just made I get 2 triggers of my message instead of the 1 when I enter the block
Hi,
Are there two or more scripts attached to the square?
no there isn’t which is why I was confused when I saw it
Log the name of the other
game object into your console to see if the player collides with the square only or if there is another game object involved.
Also log Time.frameCount
into your console to see if the messages appear in the same frame.
Alright I’ll try that out thank you
yes, it seems that the trigger happens on the same frame. I wrote the code the same in the lecture and tried rewriting it but I get the same result
What is the name of the “other” game object? Does the player collide with the same object twice?
Could you please share screenshots of what you did and see in Unity? The two game objects are interesting: their respective Inspector and their design/colliders in the scene.
Also please share your code as formatted text here.
{
void OnCollisionEnter2D(Collision2D other)
{
Debug.Log("I'm not paying for that");
}
void OnTriggerEnter2D(Collider2D other)
{
Debug.Log("What I hit?");
}
}
Can you show the components on your yellow capsule? Are there multiple colliders on it?
Both the “Square” and “The Uber eater” have got the Colission script attached. That’s why you get two messages in your console.
but the “what I hit?” is on the [OnTriggerEnter2d] would it not only trigger once as soon as I enter it? I’ve been following the lecture step by step
When the game loop dispatches collision events, both colliders involved in the collision receive calls for the event (with the other’s collider object as an argument [for triggers].)
To verify they are coming from different objects try adding + other.gameObject.name to your Debug.log, you’ll see:
“What I hit? Square” from the script component attached to The Uber eater and
“What I hit? The Uber eater” from the script component attached to the Square
I just get an error not allowing me to enter play mode in unity
Check your console to learn more about the error. If it is a compiler error, there is probably a typo in your script, which needs to be fixed first.