我想用滑鼠移動 2d 物件,但腳本不起作用。有人可以幫忙嗎?
public GameObject selectedTroup;
void Start ()
{
}
void Update()
{
Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
if (Input.GetMouseButtonDown(0))
{
Collider2D overlapObject = Physics2D.OverlapPoint(mousePos);
if (overlapObject)
{
selectedTroup = overlapObject.transform.gameObject;
Debug.Log("Hi");
}
if (Input.GetMouseButtonUp(0) && selectedTroup)
{
selectedTroup = null;
}
}
}
uj5u.com熱心網友回復:
GetMouseButtonDown():當你點擊滑鼠時只作業一次GetMouseButtonUp():當您將手指從滑鼠上移開時,只需一點GetMouseButton():只要你的手指不離開滑鼠就可以作業。
所以,如果你想移動一些東西,我建議你使用GetMouseButton()能夠移動你的物件。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/435347.html
上一篇:在統一問題中展示二叉樹
