与物体相对移动一样,物体旋转也有相对旋转,其一是自身旋转,其二是世界坐标轴旋转。
可以用一个api简单的实现这个功能——Rotate。
Rotate内设置Space.Self就是自身旋转(通常情况下都是设置为自身旋转),如果想要设置为世界坐标轴旋转的话就要改成Space.Self。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class rotate : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
Application.targetFrameRate = 60;
}
// Update is called once per frame
void Update()
{
float w = 100;
float r=w*Time.deltaTime;
this.transform.Rotate(0, -r, 0,Space.Self);
}
}