WebGL cursor Lock not working.
for some reason my cursor wont lock when play in In the webGL version of my game. Using Unity 5.4.5f1
i followed the instructions on http://docs.unity3d.com/Manual/webgl-cursorfullscreen.html but no dice.
I'm still fairly new at this and have no idea what am I doing wrong. here's the code for my cursor lock.
using UnityEngine; using System.Collections;
public class CursorToggle : MonoBehaviour {
private bool isCursorLocked;
// Use this for initialization
void Start () {
ToggleCursorState ();
}
// Update is called once per frame
void Update () {
CheckForInput ();
CheckIfCursorShouldBeLocked ();
}
void ToggleCursorState()
{
isCursorLocked = !isCursorLocked;
}
void CheckForInput()
{
if (Input.GetKeyDown (KeyCode.Tab))
{
ToggleCursorState ();
}
if (Input.GetKeyDown (KeyCode.Q))
{
ToggleCursorState ();
}
}
void CheckIfCursorShouldBeLocked()
{
if (isCursorLocked) {
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
else
{
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
}
}
}
Comment
Answer by SorenaCoder · Jul 27, 2016 at 09:56 PM
try this one , it works for me:
void OnGUI()
{
if (isCursorLocked) {
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
else
{
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
}
}