输入与控制:鼠标事件与GUI系统双击检测例子

#pragma strict

function update (){

     if(Input.GetMouseButtonDown(0))

       Debug.Log(“您在_”+Time.time+”时,按下鼠标左键”);

     if(Input.GetMouseButtonDown(1))

       Debug.Log(“您在_”+Time.time+”时,按下鼠标右键”);

     if(Input.GetMouseButtonDown(2))

       Debug.Log(“您在_”+Time.time+”时,按下鼠标中键”);

 

     if(Input.GetMouseButton (0))

       Debug.Log(“您一直按着鼠标左键”);

 

     if(Input.GetMouseButtonUp(0))

       Debug.Log(“您在_”+Time.time+”时,抬起鼠标左键”);

     if(Input.GetMouseButtonUp (1))

       Debug.Log(“您在_”+Time.time+”时,抬起鼠标右键”);

     if(Input.GetMouseButtonUp (2))

       Debug.Log(“您在_”+Time.time+”时,抬起鼠标中键”);

 

}

function onGUI()

{

var e : Event=Event.current;

     if(e.button==0 && e.isMouse){

           Debug.Log(“Left Click”);

     }else if(e.button==1){

           Debug.Log(“Right Click”);

     } else if(e.button==2){

           Debug.Log(“Middle Click”);

     } else if(e.button>2){

           Debug.Log(“Another button in the mouse clicked”);

     }

 

    if(e.isMouse&&(e.clickCount==2)){

           Debug.Log(“用户双击了鼠标”)

      }   

}

猜你喜欢

转载自blog.csdn.net/qq_15119013065/article/details/81436134
今日推荐