1.縮放相關
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Lesson8 : MonoBehaviour
{
void Start()
{
//獲取相對世界坐標系的縮放數值
print(this.transform.lossyScale);
//獲取相對本地坐標系的縮放數值(相對父物件)
print(this.transform.localScale);
//注意:1.同樣 縮放也不能單獨該x、y、z,只能一起改
// 2.相對于世界坐標系的縮放大小 只能得 不能改,所以如果要用代碼修改縮放大小,都是改相對父物件得縮放大小
// 3.Unity沒有提供關于縮放的API,之前的位移、旋轉都提供了對應的API,但縮放沒有
//直接修改范例
//this.transform.localScale = new Vector3(3, 3, 3);
//慢慢變大范例(需寫在Update里)
//this.transform.localScale += Vector3.one * Time.deltaTime;
}
}
2.看向相關
看向:讓一個物件的面朝向,一致看向某一個點 或者某一個物件
現有:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Lesson8 : MonoBehaviour
{
//要看向的一個物件
public Transform lookAtObj;
void Update()
{
//看向一個點
//傳入一個點
this.transform.LookAt(Vector3.zero);
//看向一個物件
//傳入一個物件的Transform
this.transform.LookAt(lookAtObj);
}
}
運行:

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/502924.html
標籤:其他
