京城遊戲人-Day9:Unity 中的鼠標點擊與觸摸屏點擊
-
- 作者:大銳哥
- 地址:http://blog.csdn.net/prevention
-
1、先說幾點結論
- Unity 中鼠標點擊(MouseButton)與觸摸點擊(Touch)是分開處理的,但請注意下一條。
- Unity 中鼠標點擊(MouseButton)也可以響應觸摸手勢。
- Unity 中鼠標點擊的
GetMouseButton
包含:按下去的瞬間,保持按下的狀態。 - Unity 中鼠標點擊的
GetMouseButtonDown
僅表示按下去的瞬間。 - Unity 中鼠標點擊的
GetMouseButtonUp
僅表示擡起來的瞬間。
2、一段程序驗證上面的第 4 和第 5 條
using UnityEngine;
using System.Collections;
public class GameController : MonoBehaviour
{
private int a = 0;
void Update()
{
if (Input.GetMouseButtonDown (0))
{
Debug.Log ("MOUSE BUTTON DOWN: a=" + a);
}
if (Input.GetMouseButton (0))
{
Debug.Log ("MOUSE BUTTON: a=" + a);
}
if (Input.GetMouseButtonUp (0))
{
Debug.Log ("MOUSE BUTTON UP: a=" + a);
}
a++;
}
}
打印出來的內容如下:
MOUSE BUTTON DOWN: a=74
MOUSE BUTTON: a=74
MOUSE BUTTON: a=75
MOUSE BUTTON: a=76
MOUSE BUTTON UP: a=77
可見GetMouseButtonDown
爲true
的時候,GetMouseButton
也是true
。
-
- 作者:大銳哥
- 地址:http://blog.csdn.net/prevention
-