单击并按住OnMouseDown Unity3D

时间:2015-09-21 16:10:10

标签: unity3d onmousedown

我希望我的OnMouseDown命令仅在玩家按下游戏中的对象时才能工作。此刻,玩家可以按任意位置,计时器将启动。有没有办法让计时器只在他们点击并按住一个对象时启动?为了给你一些上下文,我想让一个对象在玩家点击并保持它时变为非活动状态。

到目前为止,这是我的代码:

read -p "Did you plan on running the server from a Ramdisk?(y/n)" RAMDISK
        if [[ "$RAMDISK" == [yY] ]]; then
                read -p "What is the full path to where you would like to create the ramdisk?(/var/RAMDISK)" RAMDIR
                read -p "How big did you want the ramdisk to be?(2048)" RAMSIZE
                if [[ "$RAMSIZE" -lt 1024 ]]; then
                        $NEWRAMSIZE = $((RAMSIZE*1024)) #FIXME
                        echo $NEWRAMSIZE
                fi
                RAMDISK="Enabled"
        fi

        if [[ "$RAMDISK" == [nN] ]]; then
                RAMDISK="Disabled"
        fi
        echo $NEWRAMSIZE

1 个答案:

答案 0 :(得分:0)

解: 我使用了Raycast来做到这一点:

var ray: Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var hit : RaycastHit;   

 if (Input.GetMouseButton(0) && coll.Raycast(ray,hit,100))
 {
 timer += Time.deltaTime;
 }
 if ( Input.GetMouseButtonUp(0))
 {
    timer = 0;
 }