Hello! Got a script I wanna fire upon collision right heree…
void OnTriggerEnter(Collider col)
{
var target = col.gameObject;
var com = target.GetComponent<PlayerStateSync>();
bool isSneaking = com.crouching;
Debug.Log(isSneaking);
}
Got no errors when I compile, no errors at runtime UNTIL the collision happens and throws
NullReferenceException: Object reference not set to an instance of an object
MyScript.OnTriggerEnter (UnityEngine.Collider col) (at Assets/Game Scripts/MyScript.cs:22)
So the error is happening where I’m declaring the bool. Not really sure what’s going on… I’m guessing the error message should be self explanatory…
Hum.