Welcome!

Welcome to our community forums, full of great people, ideas and excitement. Please register if you would like to take part.

This is extra text with a test link..

Register Now

Announcement

Collapse
No announcement yet.

Cursor Locked when on Game Over Scene

Collapse
This is a sticky topic.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Cursor Locked when on Game Over Scene

    After playing the game (Using First person camera/controller) the cursor is locked when getting the the Game Over scene, and thus I am unable to click play again.

    What do I need to put in the code to unlock the cursor?

  • #2
    If you are really using a separate scene for your Game Over level you should be able to put something like this in:
    Code:
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class GameOverStart : MonoBehaviour
    {
        void Start()
        {
            Cursor.visible = true;
            Cursor.lockState = CursorLockMode.None;
        }
    }
    If you're just activating a UI over the top of everything instead, you'd need to disable the FPSController script (which is a little more tricky as that script is pretty intertwined with Unity's core). Let me know if that's the situation and we'll fix it.
    Last edited by Professor Watkins; October 22, 2020, 05:29.

    Comment


    • #3
      I was wondering if you could show me how to freeze the camera and move the mouse using a UI over the game. I would like to do that instead of a Game Over scene.

      Comment


      • #4
        Code:
        using System.Collections;
        using System.Collections.Generic;
        using UnityEngine;
        //Don't forget this to teach this script to know that it can talk to the FPSController (weird because it's part of Standard Assets)
        using UnityStandardAssets.Characters.FirstPerson;
        
        public class ReleaseMouse : MonoBehaviour
        {
            //Creating a variable to hold a First Person Controller component
            FirstPersonController fpsController;
        
            private void Start()
            {
                //Populating that variable when the game Starts (note, this means you didn't rename the FPSController from the Standard Assets (it's finding it by name))
                fpsController = GameObject.Find("FPSController").GetComponent<FirstPersonController>();
            }
        
            void Update()
            {
                if (Input.GetKeyDown(KeyCode.H)) //You don't have to listen for input...you can fire the stuff below whenever the game is over or paused or whatever
                {
                    //These three lines turns *off* the MouseLook and releases the mouse
                    fpsController.enabled = false;
                    Cursor.visible = true;
                    Cursor.lockState = CursorLockMode.None;
                }
        
                if (Input.GetKeyDown(KeyCode.F)) //This can also be triggered inside some function you call when you click a button (doesn't have to be a keypress like this)
                {
                    //These three lines turns *on* the MouseLook and releases the mouse
                    fpsController.enabled = true;
                    Cursor.visible = false;
                    Cursor.lockState = CursorLockMode.Locked;
                }
            }
        }
        Last edited by Professor Watkins; October 22, 2020, 05:30.

        Comment


        • #5
          If you're just trying to release the mouse that was locked with the FPSController, you should be able to use this:
          Code:
          using System.Collections;
          using System.Collections.Generic;
          using UnityEngine;
          using UnityStandardAssets.Characters.FirstPerson;
          
          public class ReleaseMouse : MonoBehaviour
          {
              //Creating a variable to hold a First Person Controller component
              FirstPersonController fpsController;
          
              private void Start()
              {
                  //Populating that variable when the game Starts (note, this means you didn't rename the FPSController from the Standard Assets (it's finding it by name))
                  fpsController = GameObject.Find("FPSController").GetComponent<FirstPersonController>();
              }
          
              void Update()
              {
                    fpsController.enabled = false;
                    Cursor.visible = true;
                    Cursor.lockState = CursorLockMode.None;
              }
          }

          Comment

          Working...
          X