Last active
October 15, 2019 14:56
-
-
Save sebolio/8c6f3de84dc74e1d73ffc0d6199fc892 to your computer and use it in GitHub Desktop.
Script para ocultar mouse al girar camara en uMMORPG
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Little hack to hide cursor when moving camera | |
// and then showing it on the same position it was before | |
// © seb.cl | |
// USAGE in CameraMMO.cs: | |
// `Puntero.hide();` inside the "if (Input.GetMouseButton(mouseButton))" | |
// `Puntero.show();` in an "else" of that "if" | |
using System.Runtime.InteropServices; | |
using UnityEngine; | |
public class Puntero { | |
public struct POINT { | |
public int X; | |
public int Y; | |
} | |
public static POINT PunteroOriginal; | |
public static bool PunteroOcultado = false; | |
public static void hide() { | |
#if UNITY_STANDALONE_WIN | |
if (!PunteroOcultado) { | |
POINT pt = new POINT(); | |
Puntero.GetCursorPos(out pt); | |
//Debug.Log("Hiding cursor at:" + pt.X +","+pt.Y); | |
PunteroOriginal = pt; | |
Cursor.visible = false; | |
Screen.lockCursor = true; | |
PunteroOcultado = true; | |
} | |
#else | |
//Debug.Log("Unsupported platform for Puntero"); | |
#endif | |
} | |
public static void show() { | |
#if UNITY_STANDALONE_WIN | |
if (PunteroOcultado) { | |
PunteroOcultado = false; | |
//Debug.Log("Showing cursor at "+PunteroOriginal.X+","+PunteroOriginal.Y); | |
Cursor.visible = true; | |
Screen.lockCursor = false; | |
Puntero.SetCursorPos(PunteroOriginal.X, PunteroOriginal.Y); | |
} | |
#else | |
//Debug.Log("Unsupported platform for Puntero"); | |
#endif | |
} | |
[DllImport("user32.dll")] | |
public static extern long SetCursorPos(int x, int y); | |
[DllImport("user32.dll")] | |
public static extern bool GetCursorPos(out POINT lpPoint); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment