1
嘗試在x和y軸上拖放遊戲對象。由於某些原因,即使鼠標沒有移動,隨着時間的推移,x,y和z的值也會變小。任何人都可以解釋爲什麼會發生?Unity OnMouseDrag()拖放
using UnityEngine;
using System.Collections;
public class Drag : MonoBehaviour {
Vector3 point;
float x;
float y;
float z;
void Update() {
}
void OnMouseDrag()
{
x = Input.mousePosition.x;
y = Input.mousePosition.y;
z = gameObject.transform.position.z;
point = Camera.main.ScreenToWorldPoint (new Vector3 (x, y, z));
gameObject.transform.position = point;
Debug.Log ("x: " + point.x + " y: " + point.y + " z: " + point.z);
}
}
你能指點我一些關於如何在飛機上使用光線投射的好教程嗎? –
用一個例子編輯我的答案。 –