- Home /
This question was
closed Dec 14, 2014 at 07:26 PM by
fafase for the following reason:
The question is answered, right answer was accepted
Why not showing up
Hello. I want to make a script in c# for showing up, and hiding cursor while using esc. I made it, it's hiding at first use, but don't want to show up again.Why is that?
using UnityEngine;
using System.Collections;
public class Cursor : MonoBehaviour
{
void start()
{
Screen.showCursor = false;
}
void Update()
{
if ((Input.GetKeyUp (KeyCode.Escape)) && (Screen.showCursor=false))
Screen.showCursor = true;
else
{
if ((Input.GetKeyUp (KeyCode.Escape)) && (Screen.showCursor=true))
{
Screen.showCursor = false;
}
}
}
}
Comment
Best Answer
Answer by SkaredCreations · Dec 14, 2014 at 12:24 PM
Besides the fact you're missing an equals (inside "if" you have to use "==" and not "=" else the compiler will assign the value and not check), anyway a better code will be (also take care of letter-case for the functions, it's "Start" and not "start"):
void Start ()
{
Screen.showCursor = false;
}
public void Update ()
{
if (Input.GetKeyUp(KeyCode.Escape))
Screen.showCursor = !Screen.showCursor;
}