Cursor.SetCursor not working

Okay so I’ve tried everything to get this to work but it’s not setting the cursor img whatsoever, the only way I’ve found to change the cursor is to set the default cursor itself but even then it can’t be changed afterwards. I’m using the latest version of Unity.

Has the method been redacted or updated and if so how can I solve this?

I know the raycast is working because I’m getting the detected layer printed in the console but the switch statement to change cursor is reverting to default every time.

Okay I’m an idiot so after hours spent trying to sort it last night I’ve realised as soon as I’ve tried this morning that I had the cursorAffordance script setup onto the cameraArm as opposed to on the MainCamera.

Hope no one else makes this mistake in the future but if you do this is the solution!

switch (cameraRaycaster.layerHit) {
	case Layer.Walkable:
		Cursor.SetCursor (walkcursor, hotspot, CursorMode.Auto);
		break;
	case Layer.Enemy:
		Cursor.SetCursor (enemycursor, hotspot, CursorMode.Auto);
		break;
	case Layer.RaycastEndStop:
		Cursor.SetCursor (outcursor, hotspot, CursorMode.Auto);
		break;
	default:
		print ("nothing happened");
		return;
	}

//this is what I writed about cursor affordance and it worked

As long as you have it at the same place you put the CameraRaycaster component, you’re good to go. Or if you modify the way the CursorAffordance script finds the raycaster thing.

Privacy & Terms