Hello everyone,
I’m new in unity and i’m currently trying to make my first game.
Everything seems to go good until i tried to “register” a collision between 2 objects .
The problem is that the console doesn’t show up the message “Test1” , so it means that the “OnTriggerEnter” isn’t getting executed at all.
This is the collider :
This is the player:
P.S. The player is moved to the collider using wasd.
Yes, i’ve checked the tag , but the main problem is that the “OnTriggerEnter” Method dosen’t run! I’ve put the line of code “Debug.log(“Test1”);” to test if the function actually get executed but it doesn’t show up anything in the console so i’ve to think that it isn’t working at all.
I just tried your setup and it works for me.
Did you change layers or tags? Did you change collision matrix?
Anyway, this is script I used:
using UnityEngine;
public class Collision : MonoBehaviour
{
private void OnTriggerEnter2D(Collider2D collision) {
Debug.Log("Hit!");
}
}
And this is full setup for Ground, Box and Spikes. Ground is there so Box does not fall down. Spikes is trigger, so it falls through Box and Ground. Therefore, there are to “Hit!” messages - one for Box and second for Ground:
Here it shows that you’ve taken the Rigidbody2D out of the simulation and it even puts a big warning box in the inspector to remind you what you’ve done.