
สร้างโปรเจ็กส์
- สร้างโปรเจ็กส์ชื่อ Unity Project 1
สร้างโฟลเดอร์
- สร้างโฟลเดอร์ชื่อ Script
ที่ SampleScene สร้าง Cube
- Create > 3D Object > Cube
- Reset Transform
- Add Component > New Script ชื่อ Rotator
- ลาก Rotator ไปไว้ในโฟลเดอร์ Script
- แก้ไขโค๊ด Rotator
using UnityEngine;
public class Rotator : MonoBehaviour
{
// Update is called once per frame
void Update()
{
transform.Rotate(new Vector3(15, 30, 45) * Time.deltaTime);
}
}
เมื่อรันดู Cube ก็จะหมุนไปเรื่อยๆละ