鼠标双击点击物体

var hit : RaycastHit;

 

 

private var ButtonClicked = false;

private var lastTime :float= 0;

private var nowTime :float = 0;

 

function Update ()

{

 if(Input.GetMouseButtonDown(0))

 {

  

    nowTime = Time.time;

    if (lastTime +0.3 > nowTime)

    {

     ButtonClicked = true;

    }

    else

    {

     ButtonClicked = false;

    }

    lastTime = nowTime;

    if(ButtonClicked)

    {

   var ray = Camera.main.ScreenPointToRay (Input.mousePosition);  

      if (Physics.Raycast (ray, hit))   

     { 

    var str = hit.collider.gameObject.name;

    print(str);

    //do sth

   }

  }

   }

}

posted @ 2012-04-17 16:27  渡蓝  阅读(237)  评论(0编辑  收藏  举报