您的位置:首页 > 移动开发 > Unity3D

Unity打包成APK的一些触屏操作

2015-09-15 16:55 239 查看
1.黄金矿工小游戏

点击手机屏幕,实现钩子伸出的操作

//手机控制以及电脑版本的操作控制
        if  (GameInput.IsComfirmKeyDown()&& isRotate || Input.GetKeyDown(KeyCode.Return) && isRotate || Input.GetMouseButtonDown(0) &&isRotate)
        {

            SoundPlayer.instance.Play(gouzi_down);
            isIncrease = true;
            isRotate = false;
        }


其中用到的Input.GetMouseButtonDown(0)可以实现这个功能。

2.弹珠游戏,手机触摸屏幕长按之后释放

if (state == BallState.Start || state == BallState.Restart)
        {
            if (GameInput.IsComfirmKey()||Input.GetMouseButton(0))
            {
                count++;
                if (spring.transform.GetComponent<UISprite>().height>= 60)
                    spring.transform.GetComponent<UISprite>().height -= 1;
            }
            if (GameInput.IsComfirmKeyUp()||Input.GetMouseButtonUp(0))
            {
                this.rigidbody2D.AddForce(new Vector2(0, 1) * (count*3 +80) );
                spring.transform.GetComponent<UISprite>().height = 120;
                count = 0;
                state = BallState.Shot;
            }
        }


代码片段中的Input.GetMouseButton(0)表示长按,Input.GetMouseButtonUp(0)标示弹起。

3.接金币类型小游戏,需要按钮控制人物左右移动,下面介绍NGUI的长按功能。

新建一个物体,添加UIButton组件,上面挂一个响应press的脚本,当按压记录一个bool型变量,在Update中使用此变量来控制按钮按压之后的一些效果。

public bool isPress = false;
    // Use this for initialization
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        if (isPress)
        {
            if (GetGold.instance.isMove && GetGold.instance.isUpdate)
            {
                GetGold.instance.RightMove();
            }
        }

    }

    void OnPress(bool pressed)
    {
        isPress = pressed;
    }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: