Cursor doesn't show up

I have the same code as the tutorial in DeathHandler/HandleDeath():
public void HandleDeath()

{

    gameOverCanvas.enabled = true;

    Time.timeScale = 0;

    Cursor.lockState = CursorLockMode.None;

    Cursor.visible = true;

But I can’t see the cursor after the players die. I can still shoot are pan around.

Hi,

Have you already tried to add Debug.Logs to your code to see what is going on during runtime? Maybe this code-block does not get called when your player dies.

DebugCode

I added a Debug like you suggested. It shows up in the console, but the issue persists.

Ok, now we know that the code-block got executed. Have you already tried to click the game window once? Sometimes, if Unity loses the focus, the user input does not work as expected.

For testing purposes, create a new script and a new scene. In Update, toggle the Cursor.visible value via user input. A simple if-statement and its block should do the job. Then test the script in your scene. If that works, the issue must be somewhere in or near the HandleDeath method. If the toggling in the test scene does not either, there might be a general problem in Unity.

Which version of Unity do you use?

I created a new scene and a new script:
void Start()

{

Cursor.visible = false;

}

void Update()

{

if (Input.GetKeyDown(KeyCode.Space))

{

    Cursor.lockState = CursorLockMode.None;

    Cursor.visible = true;

}

}

It works. Starts with no cursor. When I press space, the cursor shows up.

For good measure, I copy pasted the whole DeathHandler code from the resources tab, lecture changes, but it still doesn’t work.

Could you please fill out our form and send me your zipped project (without the Temp and Library folders)? Don’t forget to add a link to this thread.

When you are done, drop me a line here, so I can check our server.

I posted it.

I am using Unity 2019.4.38f1

The Unity Standard Assets FPS controller interferes with the Cursor lock state (it sets it back to locked). You have to disable the controller as well. See this post

Ok bixarrio, thanks. That worked, except I changed “gameOverCanvas.SetActive (true); → gameOverCanvas.enabled = true” because it was giving me an error. Behaves as it’s supposed to now.

I’m curious to see what solution Nina comes up with because I am a bit worried if this soultion gives me issues in the future with something else.

I’m not going to check the issue with the cursor if bixarrio’s solution worked for you. From what I understood, the problem is still the zoom? Or did I misunderstood anything?

The problem was that the cursor was not becoming visible after dying.
Using the solution bixarrio referred to, it now appears after the player dies, as it should.

Isn’t this your thread? If not, I’m sorry for the confusing. The other student linked this thread here when sharing their project with me.

[Edit:] I’ve just noticed that I opened the wrong Zombie Runner project. The mistake was on my side.

Yeah. Np.

I think we can called this solved, unless the solution doesn’t cause later issues.
I will update here if it does.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms