如何把3D Object弄成會自己旋轉呢?
首先把物件用add component 方法加上Rigidbody,之後用下面代碼新建一個cs檔案,再把新建的cs用add component 方法加進物件中。物件便會自轉了。
代碼如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class myRotation : MonoBehaviour {
private Vector3 origin;
public Rigidbody Mover;
public float speed=0.5f;
Vector3 m_EulerAngleVelocity;
void Awake() {
Mover = GetComponent<Rigidbody>();
origin=Mover.position;
}
void FixedUpdate() {
m_EulerAngleVelocity = new Vector3(0, -speed,0);
Quaternion deltaRotation = Quaternion.Euler(m_EulerAngleVelocity);
Mover.MoveRotation(Mover.rotation * deltaRotation);
}
}