Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

FirstPersonCharacter just won't let go...

Discussion in 'Scripting' started by MrBlack3d, Jun 24, 2020.

  1. MrBlack3d

    MrBlack3d

    Joined:
    Feb 5, 2019
    Posts:
    33
    Hiya Folks!

    So here's a funny scripting behavior I'm sooo close to solving but it escapes me. I have one camera attached to a empty game object that rotates around the y axis driven by buttons on the canvas. The old "orbit the building" type stuff. There's also a FPSController in the building (if you want to take a stroll).
    The code below switches the cameras. I start on the wide shot, then you change to the interior camera. Trouble is, when you change back (to the overhead cam) the mouse pointer no longer appears on the screen and I can't use that cameras controls any more. Or even go to a different scene. I can't interact with the canvas at all. It's like the FPSController won't let go of the mouse.
    I tried a version with just cameras in the code (not game objects), but found that when I did that I could translate the FPSControlled camera, but it wouldn't rotate.
    Thoughts? I suspect I'm missing something very basic.

    Cheers
    Jeff



    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class CamSwitch : MonoBehaviour
    {
    public Camera OutsideCam;
    public GameObject InsideCam;
    bool switchy = true;


    void Start()
    {
    OutsideCam.enabled = switchy;
    InsideCam.active = !switchy;
    }

    void Update()
    {
    if (Input.GetKeyDown(KeyCode.C))
    {
    switchy = !switchy;
    OutsideCam.enabled = switchy;
    InsideCam.active = !switchy;

    }


    }
    }
     
  2. Terraya

    Terraya

    Joined:
    Mar 8, 2018
    Posts:
    646
    So , if your Cursor disappear, you would need to reenable it even though i dont see anything in your script what could disable it BUT i gues you also have more scripts so maybe anywhere in there you got a function which disables it,

    Code (CSharp):
    1. Cursor.visible = true;
    should fix it
     
  3. Terraya

    Terraya

    Joined:
    Mar 8, 2018
    Posts:
    646
    https://docs.unity3d.com/ScriptReference/CursorLockMode.html

    CursorLockMode actualy make the Mouse not moveable but it doesnt hide the mouse as far as i know and it is written in the Doc
     
  4. elliotfriesen

    elliotfriesen

    Joined:
    Mar 17, 2020
    Posts:
    71
    You could also disable all effects anything has on the cursor by saying CursorLockMode.none
     
  5. elliotfriesen

    elliotfriesen

    Joined:
    Mar 17, 2020
    Posts:
    71
  6. MrBlack3d

    MrBlack3d

    Joined:
    Feb 5, 2019
    Posts:
    33
    Thanks to everybody for the guidance on this! That bit of code to unlock the cursor does work. In game play I have to hit the spacebar and the escape key for it to all fully work again, but it works! Not complaining:D

    Cheers much!