Forum rules - please read before posting.

"Leave out of cursor cycle" For Main Cursor?

Howdy, I am working on a 2D game with basic, use, look at, talk cursors, but I really don't need the main cursor. It just ends up being another click the player has to do to cycle through them all. Any way to leave it out of the cursor cycle like the other ones have an option for? Also just hiding it doesn't help, since you still have to then click thorough it. Thanks!

Comments

  • You can't omit the Main Cursor - as it's necessary for Menus - but you should be able to use a custom script to manually "skip" the Main Cursor if you're in regular gameplay.

    Something like this should do it:

    using UnityEngine;
    using AC;
    
    public class SkipMainCursor : MonoBehaviour
    {
    
        void OnEnable () { EventManager.OnChangeCursorMode += OnChangeCursorMode; }
        void OnDisable () { EventManager.OnChangeCursorMode -= OnChangeCursorMode; }
    
        void OnChangeCursorMode (int cursorID)
        {
            if (cursorID == -1)
            {
                // Main cursor
    
                if (KickStarter.playerMenus.IsMouseOverMenu ())
                {
                    return;
                }
    
                KickStarter.kickStarter.SendMessage ("CycleCursors");
            }
        }
    
    }
    
  • Thanks Chris! I'm pretty amateur when it comes to AC outside of just using the menus, so stupid question... where do I input that code? Do I just put a text file in a specific folder? Thanks!!!
  • edited February 1

    Whenever you want to use a script like this, you first need to look at the "public class" line, and create a .cs file named after it (so in this case, your file would be called SkipMainCursor.cs). Generally, this file can be placed anywhere in your project's folder structure, but there are exceptions depending on what the script does (for example, scripts that add custom features to the Unity Editor must be placed in an appropriately named folder).

    If you take a look at the public class SkipMainCursor : MonoBehaviour line again, it means that you are declaring a SkipMainCursor class that is derived from MonoBehaviour. Among other things, being derived from Monobehaviour means that the script can be added to a GameObject as a component. So once you create the script, for it to have any effect at runtime, it must be present in the scene you are running as a component attached to a GameObject.

    Now, WHICH object you need to attach the script to depends on what the rest of the script says. Some scripts make reference to the object they are attached to, so they must be added to a specific GameObject to work properly. But the SkipMainCursor.cs script Chris has just provided doesn't make reference to any specific GameObject.

        void OnEnable () { EventManager.OnChangeCursorMode += OnChangeCursorMode; }
        void OnDisable () { EventManager.OnChangeCursorMode -= OnChangeCursorMode; }
    

    This bit of code does two things: when the GameObject the script is attached to is enabled, it hooks itself to an AC event that fires whenever the cursor mode is changed (the OnChangeCursorMode event). And when the object is disabled, it unhooks itself from the AC event. The rest of the script then states what happens when that event is fired.

    I'm not too knowledgeable about AC cursors, but from what I gather here, the ID for AC's main cursor is -1. So this is what the script is saying: when the AC event is fired, check if the cursor is the main cursor. If it IS the main cursor, check if the mouse is over a menu - if yes, do nothing; if not, then immediately cycle the cursor so that it isn't the main cursor anymore.

    In short, you just need to attach the script to any GameObject in the scene for it to work. If you need it to work in more than one scene, you can either add the script to all of them individually, or add it once to an object that survives scene changes (for example, the player prefab).

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.