一、角度相關
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Lesson7 : MonoBehaviour
{
void Start()
{
//相對世界坐標的角度
//想要得到Inspector面板上顯示的角度,并非使用transform.rotation,而是transform.eulerAngles
print(this.transform.eulerAngles);
//相對父物件的角度
print(this.transform.localEulerAngles);
//注意:1.同位置一樣,角度也無法單獨對x、y、z其中一個值進行修改,只能使用Vector3進行整體修改
// 2.通過歐拉角得到的角度 不會出現負數,雖然Inspector顯示出了負數,但是 通過此代碼得到的歐拉角 始終 都是0~360
}
}
二、旋轉相關
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Lesson7 : MonoBehaviour
{
void Update()
{
//自己手動計算:省略,和位置的計算差不多,不停改變角度即可
//用API計算
//1.自轉
//引數1 旋轉的角度 和 旋轉的速度
//引數2 相對哪個坐標系旋轉(默認不填 就是相對于自己的坐標系進行旋轉)
this.transform.Rotate(new Vector3(0, 5, 0) * Time.deltaTime, Space.World);
//補充:另外一種寫法
//相對于某個軸轉
//引數1 相對于哪個軸旋轉
//引數2 旋轉的角度 和 旋轉的速度
//引數3 相對哪個坐標系旋轉(默認不填 就是相對于自己的坐標系進行旋轉)
this.transform.Rotate(Vector3.right, 10 * Time.deltaTime, Space.World);
//2.相對于某一個點旋轉
//引數1 先對于哪個點旋轉
//引數2 相對于引數1的那個點 的 哪一個軸旋轉
//引數3 旋轉的角度 和 旋轉的速度
//這樣寫 就是相對于(0, 0, 0)點 的 y軸 進行旋轉
this.transform.RotateAround(Vector3.zero, Vector3.up, 50 * Time.deltaTime);
}
}

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/502141.html
標籤:其他
上一篇:Kubernetes-概述
下一篇:回歸與分類
