Hi!
I am new at programming and I have a problem with showing and locking the cursor when I want. Now my cursor in menu isn’t showing at all but it works fine in pause screen and in the game.
Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class CursorLock : MonoBehaviour
{
Scene currentScene;
string sceneName;
// Start is called before the first frame update
void Start()
{
// Create a temporary reference to the current scene.
currentScene = SceneManager.GetActiveScene();
// Retrieve the name of this scene.
string sceneName = currentScene.name;
}
private void Update()
{
if (sceneName == "Main Menu" || PauseMenu.GameIsPaused == true)
{
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
}
else
{
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
}
}
}
I would greatly appreciate if you could help me :).
Sorry for my bad English.