我想在桌面以及触控/平板电脑环境中测试我的脚本。因此,我需要在我的脚本中将mouseinputs转换为Touch。我试过了:
var screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);
Touch touchZero = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
它表示无法隐式转换类型UnityEngine.Vector3' to
UnityEngine.Touch'
有机会以某种方式转换类型,所以我不必写两次所有内容吗?
答案 0 :(得分:0)
您可以通过以下鼠标输入构建触摸:
Touch fakeTouch = new Touch ();
fakeTouch.fingerId = 10;
fakeTouch.position = Input.mousePosition;
fakeTouch.deltaTime = Time.deltaTime;
fakeTouch.deltaPosition = Input.mousePosition - lastMousePosition;
fakeTouch.phase = (Input.GetMouseButtonDown (0) ? TouchPhase.Began :
(fakeTouch.deltaPosition.sqrMagnitude > 1f ?
TouchPhase.Moved : TouchPhase.Stationary));
fakeTouch.tapCount = 1;