Add a liberal use of Debug.Log to see what is actually happening. Make sure anything you want to detect collisions with has the correct tag. Make sure you’ve spelled the tag correctly in code (Obstacle is spelled wrong, so might be the issue). Make sure you have rigidbody components on everything needed, with correct settings. Otherwise please state exactly what is going wrong beyond you just can’t get it to work.
I cant find out whats wrong and if you look at line 13 “GameManager” has “EndGame” and that puts “END GAME” in Console, ive tested “EndGame” and it works but uhh yeah… Dosen’t work in this script.
using UnityEngine;
public class PlayerCollision : MonoBehaviour {
public PlayerStuff movement;
void OnCollisionEnter (Collision collisionInfo)
{
Debug.Log("PlayerCollision.OnCollisionEnter called");
if (collisionInfo.collider.tag == "Obsticle")
{
Debug.Log("Collided with an Obsticle");
movement.enabled = false;
FindObjectOfType<GameManager>().EndGame();
}
else
{
Debug.Log("Did not collide with an Obsticle");
}
}
}
This will let you know if your collisions are registering at all, and if the correct tag is being found. Also again verify that you have that tag actually set to that misspelling of Obstacle on the objects you are colliding with.
Lastly, verify you don’t have any console errors. If FindObjectOfType fails, and since you are calling EndGame on it even if it does fail, you will get a null reference error in the console or the player log.
Hi! Soooooooooo I changed my code and first I get the error:The referenced script on this Behaviour (Game Object ‘Obsticle (4)’) is missing! And im also not getting any Collided With An Obsticle