[英]How do you get the position of the mouse on screen with C# in MacOS?
Without using Cocoa/XCode, is there a way I can get the position of the mouse cursor in C# (MacOS)?在不使用 Cocoa/XCode 的情况下,有没有办法在 C# (MacOS) 中获取鼠标光标的位置? It needs to be Unity-Compatible.
它需要与 Unity 兼容。
Taken from https://docs.unity3d.com/ScriptReference/Input-mousePosition.html取自https://docs.unity3d.com/ScriptReference/Input-mousePosition.html
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour
{
public GameObject particle;
void Update()
{
if (Input.GetButtonDown("Fire1"))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray))
Instantiate(particle, transform.position, transform.rotation);
}
}
}
or taken from https://stackoverflow.com/a/46999239/12808204或取自https://stackoverflow.com/a/46999239/12808204
//the object to move
public Transform objectToMove;
void Update()
{
Vector3 mouse = Input.mousePosition;
Ray castPoint = Camera.main.ScreenPointToRay(mouse);
RaycastHit hit;
if (Physics.Raycast(castPoint, out hit, Mathf.Infinity))
{
objectToMove.transform.position = hit.point;
}
}
Or if you're looking for more specifically an OS API implementation, not necessarily for unity, check Getting "global" mouse position in Mac OS X Not to be that guy, but at least try to google it before making a question thread.或者,如果您正在寻找更具体的 OS API 实现,不一定是为了统一,请检查在 Mac OS X 中获取“全局”鼠标位置不要成为那个人,但至少在提出问题之前尝试谷歌它。 These where all top google results.
这些都是谷歌搜索结果的前列。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.