由于用Rotation旋转比较麻烦,所以使用欧拉角。
也就是下面的localEulerAngles获取本物体的三个角。
然后再设置一个角速度w,用角速度和Time.deltaTime计算转动的角度,然后以y轴为轴心进行匀速旋转。
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;
Vector3 angles = this.transform.localEulerAngles;
angles.y += r;
this.transform.localEulerAngles = angles;
}
}