Forum rules - please read before posting.

Stopping the camera following the cursor.

Hello.
Sorry for my english.

When I enable the Follow Cursor setting in the Game Camera 2d component.

Is it possible to stop the camera following the cursor when hovering the mouse over a certain tagged hotspot. At the same time, so that the camera movement resumes if I remove the cursor from the hotspot.

Thanks

Comments

  • You can't pause the effects of the cursor on the camera - reducing the panning factor or disabling it will cause the camera to revert to its original position.

    You'd instead have to switch to a separate Camera that's positioned over the Hotspot.

    To do so when a given Hotspot is selected, attach a custom script to it that hooks into the OnHotspotSelect / OnHotspotDeselect custom events:

    using UnityEngine;
    using AC;
    
    public class HotspotCamera : MonoBehaviour
    {
    
        public GameCamera2D normalCamera;
        public GameCamera2D hotspotCamera;
        public float transitionTime = 0.3f;
    
        void OnEnable ()
        {
            EventManager.OnHotspotSelect += OnHotspotSelect;
            EventManager.OnHotspotDeselect += OnHotspotDeselect;
        }
    
        void OnDisable ()
        {
            EventManager.OnHotspotSelect -= OnHotspotSelect;
            EventManager.OnHotspotDeselect -= OnHotspotDeselect;
        }
    
        void OnHotspotSelect (Hotspot hotspot)
        {
            if (hotspot.gameObject == gameObject && KickStarter.mainCamera.attachedCamera == normalCamera)
            {
                KickStarter.mainCamera.SetGameCamera (hotspotCamera, transitionTime);
            }
        }
    
        void OnHotspotDeselect (Hotspot hotspot)
        {
            if (hotspot.gameObject == gameObject && KickStarter.mainCamera.attachedCamera == hotspotCamera)
            {
                KickStarter.mainCamera.SetGameCamera (normalCamera, transitionTime);
            }
        }
    
    }
    
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.