I'm currently working on a 2D game in Unity, and my current script is pretty simple. The objective of the game is to maneuver an object (player) through obstacles (leftObstacle and rightObstacle), but my problem is that whenever the player gets hit by an obstacle, which it detects by looking for the GameObject's name, nothing happens.
I've reread my code many times to look for wrong object references in the script, but also in the inspector, and I couldn't find any real mistakes. All of the objects also have an attached rigid body.
Here's the excerpt of the player script, where everything seems to be well referenced:
public class playerScript : MonoBehaviour
{
float playerPositionX;
float playerSpeed;
public bool playerEliminated;
public GameObject leftObstacle;
public GameObject rightObstacle;
public GameObject Player;
Here's the excerpt of the left obstacle's script, where it needs to be looking for a collision:
public class obstacleScript : MonoBehaviour
{
float y;
public GameObject Player;
public GameObject leftObstacle;
public GameObject rightObstacle;
double currentHeightY;
public float leftObstacleX;
void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.name == "Player")
{
Debug.Log("collision");
}
}
I'm not including the excerpt of the right obstacle's script, since the code there is pretty much the same as the left obstacle.
Pictures of the player object in the inspector:

