Di video tutorial ini saya akan berbagi pengetahuan game development Unity tentang cara membuat pesawat terbang yang bisa kamu kendalikan dengan memencet tombol WASD di keyboard.
Berikut ini script Pesawat.cs yang kamu lihat di video di atas:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Pesawat : MonoBehaviour
{
public float kecepatan = 10f;
Rigidbody rb;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
rb.velocity = transform.forward * kecepatan;
if(Input.GetKey(KeyCode.W)){
transform.Rotate(.1f,0,0);
}
if(Input.GetKey(KeyCode.S)){
transform.Rotate(-.1f,0,0);
}
if(Input.GetKey(KeyCode.A)){
transform.Rotate(0,0,.6f);
}
if(Input.GetKey(KeyCode.D)){
transform.Rotate(0,0,-.6f);
}
}
}