Forum rules - please read before posting.

Switching hotspot detection method.

Heya,

My game uses Player Vicinity as hotspot detection method and it works great, however I would love to be able to use Mouse Over detection in some selected scenes. Is this possible or is this a global setting that's set in stone for the whole game?

Tanks!

t

Comments

  • Yes, it's possible. Any Manager field can be altered at runtime through scripting. Just right-click the field label to get an API reference to it. To switch to Mouse Over, the code would be:

    AC.KickStarter.settingsManager.hotspotDetection = HotspotDetection.MouseOver;
    

    The only thing to keep in mind is that this will alter the Manager asset file - so it won't revert back when exiting Play Mode. As such, you'll need to set this to your intended initial value when the game begins.

  • Thanks, Chris!

    And with the risk of sounding as a complete imbecile, how do I run this code? I'd like to run it from an action list. I've done everything 100% through action lists so far and haven't had to use a line of actual code as of yet. (Praise the maker!)

  • edited February 2021

    If I may help.
    1. Create a script with the code.
    2. Attach it to an empty object, prefab it and delete that scene object.
    3. Create a global variable bool MouseOverDetection(your ID of this variable).
    4. When you run it set your variable MouseOverDetection (true or false) accordingly to your needs and then add the prefab with the script to the scene.
    5. Do not forget to revers it to it's initial value when you don't need it.

    The script might look something like this:

        using UnityEngine;
        using System.Collections;
    
        namespace AC{
            public class MouseOverDetection: MonoBehaviour  {
    
        public bool MouseOverDetection; 
    
                void start (){
    
         MouseOverDetection = GlobalVariables.GetBooleanValue (your ID of MouseOverDetection  variable); 
                    if (MouseOverDetection == false) 
                    {
                        // Set Mouse Over Detection On 
         AC.KickStarter.settingsManager.hotspotDetection = HotspotDetection.MouseOver;
                        GlobalVariables.SetBooleanValue(your ID of MouseOverDetection  variable, true);
                    }
                    else 
                    {       
                // Set Mouse Over Detection Off 
    
     AC.KickStarter.settingsManager.hotspotDetection = HotspotDetection.PlayerVicinity;
                        GlobalVariables.SetBooleanValue(your ID of MouseOverDetection  variable, false);
    
                    }
                    return 0f;
    
               }
            }
        }
    

    I haven't tried it, but this might give you some ideas.

  • If you want to have it as a per-scene setting, then as SkyTree writes, you don't need to have it be part of an ActionList - simply calling it in the Start function of a script present in the scene itself would be enough. A trimmed version of the script would be:

    using UnityEngine;
    using AC;
    
    public class MouseOverDetection: MonoBehaviour 
    {
    
        public HotspotDetection hotspotDetection;
    
        void Start ()
        {
            KickStarter.settingsManager.hotspotDetection = hotspotDetection;
        }
    
    }
    

    This would cause the field to be set when the scene begins, but if you do want to rely on an ActionList, you can either write a custom Action, or simply have your ActionList trigger code in a separate script.

    To do this, you would first make the intended script function public (i.e. replace the above: "void Start" with "public void Run"), and then use either the Object: Send message or Object: Call event Action to trigger the component's "Run" function.

  • edited February 2021

    Thanks, guys! I like the idea of being able to swap mode mid-scene, actually. And attaching the script to a prefab and then dropping that prefab in the scene seems like a simple way of doing so, from action lists. I imagine I would have two separate prefabs, one for mouse over and one for vicinity.

    But when I put this:

    using UnityEngine;
    using AC;
    
    public class MouseOverDetection: MonoBehaviour 
    {
    
        public HotspotDetection hotspotDetection;
    
        void Start ()
        {
            KickStarter.settingsManager.hotspotDetection = HotspotDetection.PlayerVicinity;
        }
    
    }
    

    in a .cs file and try to drag that onto any object in my scene, unity tells me "The script don't inherit a native class that can manage a script". What does this mean? And lol why the unprovoked cowboy accent on this error message?

    Knee deep in adventure game dev on a friday night. It just doesn't get any better! :smile:

  • You'll need to make sure your script name matches the class. Is your file named MouseOverDetection.cs?

  • That was it. Heh I've never done this before so I had zero clue that this was a necessity, but I see now why that would make sense. :blush:

    Feeling like a straight up hackerman genius now that I've also added the CursorDisplay setting to my scripts as well so that the cursor is hidden when going into player vicinity mode and visible when using mouse detection. Works like a charm.

    Big thanks for all the help!

    t

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.