Cursor doesn't revert after clicking

Once I had implemented the code, I could select the ability in the action bar (the cursor turns to the selected icon) and then click somewhere to confirm target. However, the cursor didn’t revert back to the original after I clicked.

Upon investigation, I found in my PlayerController.cs the SetCursor method had this code:

        private void SetCursor(CursorType type)
        {
            if (currentCursor == type) { return; }
            CursorMapping mapping = GetCursorMapping(type);
            Cursor.SetCursor(mapping.texture, mapping.hotspot, CursorMode.Auto);
            currentCursor = type;
        }

Getting rid of the if statement and currentCursor = type lines fixed the issue.

Not sure if this was something I missed from the earlier lectures or not, but thought it might help anyone having similar issues.

I’d be interested in knowing if there was a performance hit to this approach. The reason this is there is to avoid spamming the Cursor.SetCursor every frame, only changing it when needed.

Thanks, Brian. I’ll take a look to see if I can work out how to trigger a cursor change without spamming it every frame

I found that playerController.enabled = false; just disable Behaviour methods (Start, Update), but other methods (such as playerController.SetCursor() ) are available to use.

In DelayedClickTargeting.cs, change

Cursor.SetCursor(cursorTexture, cursorHotspot, CursorMode.Auto)

To

playerController.SetCursor(cursorType) ;

if you declare cursorType as an attribute in class DelayedClickTargeting.cs, make sure that it is a constant or readonly

const CursorType cursorType = CursorType.DelayedClickTargeting;

Finally, define cursorTexture, and cursorHotspot for CursorType.DelayedClickTargeting in PlayerController component.

3 Likes

That’s a nice approach, and you’re correct, all disabling a script does is turn off the Unity callbacks (except Awake, I believe). Fun unrelated fact: If you made Update a public method, you could call it on a disabled component manually (but don’t).

1 Like

Privacy & Terms