unity3d Input.GetMouseButton 用法

分类栏目:unity3d教程

182

unity3d  Input.GetMouseButton 的用法和解释

button 值为 0 表示左按钮,1 表示右按钮,2 表示中间按钮。按下鼠标按钮时返回 true,释放时返回 false

using UnityEngine;
using System.Collections;
// Detects clicks from the mouse and prints a message
// depending on the click detected.
public class ExampleClass : MonoBehaviour {
    void Update()
    {
        if (Input.GetMouseButton(0))
        { Debug.Log("Pressed left click.");
        }
        if (Input.GetMouseButton(1))
        { Debug.Log("Pressed right click.");
        }
        if (Input.GetMouseButton(2))
        { Debug.Log("Pressed middle click.");
        }
    }
}