using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.InteropServices;
public class Mousepause : MonoBehaviour
{
[DllImport("user32.dll", EntryPoint = "SetCursorPos")]
public static extern int SetCursorPos(int x, int y);
public bool ck = false;
// Use this for initialization
void Start () {
SetCursorPos(200,200);
}
// Update is called once per frame
void Update () {
if(!ck)
{
if(Input.mousePosition.x<1)
{
//Mathf.RoundToInt数学算法,取整
SetCursorPos(Mathf.RoundToInt(Screen.width * 0.5f), Mathf.RoundToInt(Input.mousePosition.y));
}
if(Input.mousePosition.y<1)
{
SetCursorPos(Mathf.RoundToInt(Input.mousePosition.x), Mathf.RoundToInt(Screen.height * 0.5f));
}
if(Input.mousePosition.x>Screen.width-5)
{
SetCursorPos(Mathf.RoundToInt(Screen.width * 0.5f), Mathf.RoundToInt(Input.mousePosition.y));
}
}
}
private void OnApplicationFocus()
{
ck = !ck;
}
}
unity设置鼠标按键焦点事件
最新推荐文章于 2025-06-09 19:55:12 发布