超级简单,但是注意,有坑!
首先创建一个脚本,把下面的代码复制进去就好啦,注意类名要和脚本名一样哦,自己改一下就好啦!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class xz : MonoBehaviour
{
float speed = 0.1f;
void Update()
{
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved)
{
//得到手指在这一帧的移动距离
Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;
//在X 轴上旋转物体
// GameObject.Find("zhuan/Kazuko").transform.Rotate(0, touchDeltaPosition.x, 0);
transform.Rotate(0, -touchDeltaPosition.x, 0);
}
}
}
然后再把这个脚本拖到你想让他旋转的物体上就OK!
接下来就是坑了,弄完之后你在电脑上调试的时候你会发现转不动,这是正常的,打包成app安装在手机上就可以转动了!