Unity的C#編程教程_9_Quaternion Identity(四元數同一性)
- 2020 年 7 月 19 日
- AI
- C/C++/C#
- 創建一個 C# Script 腳本,用於生成 Cube
- 把腳本掛到 Main Camera 下
- 腳本中創建變數,並把 cube 預製件拖進去
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpawnCube : MonoBehaviour
{
[SerializeField]
private GameObject cubePrefeb;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
//Instantiate(cubePrefeb, Vector3.zero, Quaternion.identity);
// Quaternion.identity 代表沒有旋轉
Instantiate(cubePrefeb, Vector3.zero, Quaternion.Euler(0, 0, 30));
// 生成 cube,繞著 z 軸旋轉 30度
}
}
}
- 開始遊戲,按下空格鍵,生成的 cube 可以看到,z 軸的旋轉角度是 30