For some reason, which I haven’t been able to figure out, my attempts to call OnDelegateCalled() are not working.
CameraRaycaster:
public delegate void OnLayerChange(); //Declare new delegate type
public OnLayerChange layerChangeObservers; //Instatiate Observer set
void SomeLayerChangeHandler()
{
print ("SomeLayerChangeHandler() I handled it!");
}
void Start()
{
viewCamera = Camera.main;
layerChangeObservers += SomeLayerChangeHandler; // Add to set of handling functions
layerChangeObservers(); // Call the delegates
}
CursorAffordance:
CameraRaycaster cameraRaycaster;
// Use this for initialization
void Start () {
cameraRaycaster = GetComponent<CameraRaycaster>();
cameraRaycaster.layerChangeObservers += OnDelegateCalled;
}
// Is called when layer changes
void OnDelegateCalled()
{
print("OnDelegateCalled has worked");
switch (cameraRaycaster.currentLayerHit)
{
case Layer.Walkable:
Cursor.SetCursor(walkCursor, cursorHotspot, CursorMode.Auto);
break;
case Layer.Enemy:
Cursor.SetCursor(targetCursor, cursorHotspot, CursorMode.Auto);
break;
case Layer.RaycastEndStop:
Cursor.SetCursor(unknownCursor, cursorHotspot, CursorMode.Auto);
break;
default:
Debug.LogError("Don't know what cursor to show");
return;
}
}
I also created a test script, the test script does work as intended.
TestScript:
public class DelegateTest : MonoBehaviour {
CameraRaycaster cameraRaycaster;
// Use this for initialization
void Start () {
cameraRaycaster = GetComponent<CameraRaycaster>();
cameraRaycaster.layerChangeObservers += TestMethod;
}
// Update is called once per frame
void TestMethod () {
print("Test method has been run");
}
I get the print of “SomeLayerChangeHandler() I handled it!”, and, “Test method has been run”, but not, “OnDelegateCalled has worked”
Any help would be appreciated!
Thanks.