首页 > 解决方案 > 如何在移动设备上仅旋转屏幕的一部分的播放器(立方体)?

问题描述

如果我触摸屏幕并将手指移动到屏幕的某一部分,我不知道如何旋转播放器。 https://imgur.com/1xDSWtA这是我要旋转立方体的部分。

标签: c#unity3d

解决方案


将脚本添加到多维数据集,如下所示:

void Update()
{
    if(Input.touches > 0)
    {
        Touch touch = Input.GetTouch(0);
        Vector2 pos = touch.position;
        float width_fraction = pos.x / (float)Screen.width;

        // only run this, if finger is on the right half (50%)
        if(width_fraction > 0.5)
        {
            this.transform.Rotate(0, Time.deltatime * 30f, 0); // rotate 30 Deg per second
        }
    }
}

推荐阅读