Ok, so we know that your subscribing methods are not subscribing as you would like… let’s see if we can work out why.
The only thing which is trying to subscribe is the CursorAffordance.cs script, so, obvious first question, is the CursorAffordance
script actually attached to a GameObject?
Assuming it is, in it’s Start
method you are retrieving the CameraRaycaster component, if this wasn’t found and you tried to access its onLayerChange
variable you would expect to see an error, so I’m going to assume that the component is found from your main camera. If you wanted to be sure, you could apply the same kind of test again, e.g. ;
void Start ()
{
cameraRaycaster = Camera.main.GetComponent<CameraRaycaster>();
if(cameraRaycaster != null)
{
cameraRaycaster.onLayerChange += OnLayerChanged;
}
else
{
Debug.Log("I didn't find the CameraRaycaster");
}
}
You are wiring up the OnLayerChanged
method from the CursorAffordance.cs script within the Start
method, so if we now take a look at that, nothing is really jumping out at me and suggesting a problem, although the default
condition is a bit pointless at the moment, as if the logic were to fall into that I don’t think you would see anything in the console at all, it would be best to put something in that LogError
statement;
default:
Debug.LogError("Unable to determine layer");
return;
If you have PauseOnError enabled then this may not be an issue for you, but worth considering.
Another point of testing here, you could comment out that entire switch statement and just put a Debug
statement in there, a handy way to see if it is getting called at all, e.g.
void OnLayerChanged(Layer newLayer)
{
Debug.Log("CursorAffordance : OnLayerChanged called");
}
If you made this quick change, does this message appear in the console when you run the game?