Skip to content

Instantly share code, notes, and snippets.

@melv-n
Last active October 28, 2016 11:07
Show Gist options
  • Select an option

  • Save melv-n/65c7494ecbacf11ea4910100d446f54e to your computer and use it in GitHub Desktop.

Select an option

Save melv-n/65c7494ecbacf11ea4910100d446f54e to your computer and use it in GitHub Desktop.

Revisions

  1. Melvin revised this gist Oct 28, 2016. 1 changed file with 7 additions and 4 deletions.
    11 changes: 7 additions & 4 deletions Main.cs
    Original file line number Diff line number Diff line change
    @@ -12,23 +12,26 @@ void OnGUI() {
    // When entered with CLICK: Releases Pointer Lock but does not Reveal Cursor.
    // When entered with Q: Works as intended. Released Pointer Lock and Reveals the Cursor.
    if (Input.GetKeyDown(KeyCode.O)) {
    Cursor.lockState = CursorLockMode.None;
    Cursor.visible = true;
    ExitPointerLock();
    }

    // ESC: Exit PointerLock state
    // When entered with CLICK: Releases Pointer Lock but does not Reveal Cursor.
    // When entered with Q: On FIRST press it Releases Pointer Lock (cursor still hidden), on SECOND press it Reveals the Cursor!
    if (Input.GetKeyDown(KeyCode.Escape)) {
    Cursor.lockState = CursorLockMode.None;
    Cursor.visible = true;
    ExitPointerLock();
    }
    }

    void EnterPointerLock() {
    Cursor.lockState = CursorLockMode.Locked;
    Cursor.visible = false;
    }

    void ExitPointerLock() {
    Cursor.lockState = CursorLockMode.None;
    Cursor.visible = true;
    }

    public override void OnPointerDown(UnityEngine.EventSystems.PointerEventData eventData) {
    EnterPointerLock();
  2. Melvin revised this gist Oct 28, 2016. 1 changed file with 18 additions and 11 deletions.
    29 changes: 18 additions & 11 deletions Main.cs
    Original file line number Diff line number Diff line change
    @@ -3,27 +3,34 @@

    public class Main : Button {
    void OnGUI() {
    // Exit PointerLock state (works when entered with Q)
    // Q: Enter PointerLock state
    if (Input.GetKeyDown(KeyCode.Q)) {
    EnterPointerLock();
    }

    // O: Exit PointerLock state
    // When entered with CLICK: Releases Pointer Lock but does not Reveal Cursor.
    // When entered with Q: Works as intended. Released Pointer Lock and Reveals the Cursor.
    if (Input.GetKeyDown(KeyCode.O)) {
    Cursor.lockState = CursorLockMode.None;
    Cursor.visible = true;
    }

    // Enter PointerLock state
    if (Input.GetKeyDown(KeyCode.Q)) {
    Cursor.lockState = CursorLockMode.Locked;
    Cursor.visible = false;
    }

    // Exit PointerLock state

    // ESC: Exit PointerLock state
    // When entered with CLICK: Releases Pointer Lock but does not Reveal Cursor.
    // When entered with Q: On FIRST press it Releases Pointer Lock (cursor still hidden), on SECOND press it Reveals the Cursor!
    if (Input.GetKeyDown(KeyCode.Escape)) {
    Cursor.lockState = CursorLockMode.None;
    Cursor.visible = true;
    }
    }

    void EnterPointerLock() {
    Cursor.lockState = CursorLockMode.Locked;
    Cursor.visible = false;
    }

    public override void OnPointerDown(UnityEngine.EventSystems.PointerEventData eventData) {
    Cursor.lockState = CursorLockMode.Locked;
    Cursor.visible = false;
    EnterPointerLock();
    }
    }
  3. Melvin revised this gist Oct 28, 2016. 1 changed file with 15 additions and 2 deletions.
    17 changes: 15 additions & 2 deletions Main.cs
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,29 @@
    using UnityEngine;
    using UnityEngine.UI;
    using System.Runtime.InteropServices;

    public class Main : Button {
    void OnGUI() {
    if (Input.GetKeyDown(KeyCode.Escape)) {
    // Exit PointerLock state (works when entered with Q)
    if (Input.GetKeyDown(KeyCode.O)) {
    Cursor.lockState = CursorLockMode.None;
    Cursor.visible = true;
    }

    // Enter PointerLock state
    if (Input.GetKeyDown(KeyCode.Q)) {
    Cursor.lockState = CursorLockMode.Locked;
    Cursor.visible = false;
    }

    // Exit PointerLock state
    if (Input.GetKeyDown(KeyCode.Escape)) {
    Cursor.lockState = CursorLockMode.None;
    Cursor.visible = true;
    }
    }

    public override void OnPointerDown(UnityEngine.EventSystems.PointerEventData eventData) {
    Cursor.lockState = CursorLockMode.Locked;
    Cursor.visible = false;
    }
    }
  4. Melvin revised this gist Oct 28, 2016. 1 changed file with 0 additions and 5 deletions.
    5 changes: 0 additions & 5 deletions Main.cs
    Original file line number Diff line number Diff line change
    @@ -3,11 +3,6 @@
    using System.Runtime.InteropServices;

    public class Main : Button {
    #if UNITY_WEBGL
    [DllImport("__Internal")]
    private static extern void SendClientHeartbeat(string _msg);
    #endif

    void OnGUI() {
    if (Input.GetKeyDown(KeyCode.Escape)) {
    Cursor.lockState = CursorLockMode.None;
  5. Melvin created this gist Oct 28, 2016.
    21 changes: 21 additions & 0 deletions Main.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    using UnityEngine;
    using UnityEngine.UI;
    using System.Runtime.InteropServices;

    public class Main : Button {
    #if UNITY_WEBGL
    [DllImport("__Internal")]
    private static extern void SendClientHeartbeat(string _msg);
    #endif

    void OnGUI() {
    if (Input.GetKeyDown(KeyCode.Escape)) {
    Cursor.lockState = CursorLockMode.None;
    Cursor.visible = false;
    }
    }

    public override void OnPointerDown(UnityEngine.EventSystems.PointerEventData eventData) {
    Cursor.lockState = CursorLockMode.Locked;
    }
    }