Forum rules - please read before posting.

Mouse right click to lock cursor?

Hi,
I refer to first-person-game cursor movement/lock.
Currently when you click on the option 'Lock cursor in screen's centre when game begins?' you need to click a button (or click the mouse if mapped) to unlock the cursor. The cursor is either locked or unlocked till you toggle the cursor.
What I want to achieve is this: When you right click on the mouse you lock the cursor but this is only for as long as you keep holding the right mouse. When you release the mouse it automatically toggles the cursor to unlock. Hold the right mouse again, and again the cursor will automatically lock.
How can I achieve this?
Many Thanks,

Comments

  • Give this custom script (FreeAimWhenMouseHeld.cs) a try:

    using UnityEngine;
    using AC;
    
    public class FreeAimWhenMouseHeld : MonoBehaviour
    {
    
        void Update ()
        {
            if (!KickStarter.stateHandler.IsInGameplay ())
            {
                KickStarter.playerInput.SetInGameCursorState (false);
                return;
            }
    
            if (Input.GetMouseButtonDown (1))
            {
                if (KickStarter.playerInteraction.GetActiveHotspot () == null)
                {
                    KickStarter.playerInput.SetInGameCursorState (true);
                    KickStarter.playerInput.ResetClick ();
                    KickStarter.playerInput.ResetMouseClick ();
                }
            }
    
            if (Input.GetMouseButtonUp (1))
            {
                KickStarter.playerInput.SetInGameCursorState (false);
                KickStarter.playerInput.ResetClick ();
                KickStarter.playerInput.ResetMouseClick ();
            }
        }
    }
    

    Just attach it to a new GameObject in the scene - is that the kind of behaviour you're after?

  • Hi Chris,
    Perfect exactly as I wanted it.

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.