Mouse Cursor Problem
I'm currently attempting to write a script that, when a certain UI element is activated, it will allow the player to press the 'E' key to switch cameras to a camera named cam2. So far I am successful, except for one aspect:
The cursor does not show up. I believe that this is due to the fact that the camera is switching from the default FPSController because, when I disable the First Person Controller script in edit mode, the cursor will show up. I tried adding the line:
Cursor.visible = true;
at the end of the IF statement. By using Debug.Log, I have confirmed that the line of code is executing successfully, but the mouse cursor doesn't appear to actually be appearing once again. I've even attempted to deactivate the FPSController entirely, which I have successfully done so, but the mouse cursor remains invisible. Here's my complete code below:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CameraSwitch : MonoBehaviour {
public Text activateText;
public GameObject Jim;
public Camera cam1;
public Camera cam2;
public GameObject player;
// Use this for initialization
void Start ()
{
cam1.enabled = true;
cam2.enabled = false;
}
// Update is called once per frame
void Update ()
{
if (Input.GetKeyDown("e"))
{
Debug.Log("E Pressed!");
if (activateText.enabled == true)
{
cam1.enabled = !cam1.enabled;
cam2.enabled = !cam2.enabled;
player.SetActive(true);
if (cam2.enabled == true)
{
Cursor.visible = true;
Debug.Log("Cursor should be enabled!");
player.SetActive(false);
}
}
}
}
}
Any ideas on how to fix this?
Have you tried, Cursor.SetCursor()? and force it to the middle of the screen ?
Toggling visible should be fine. When and where is the false set called? I bet it's executed too and after this setting true.
Your answer
Follow this Question
Related Questions
How to make a button control Animator animation 0 Answers
Collision Issue! PLEASE GUYS HELP ME! 3 Answers
How would i modify my current script to remove these UI buttons without killing my pause menu? 1 Answer
Problems with UI buttons and Cursor position (or) UI buttons and instantiated canvas. 1 Answer