在unity中编写了控制飞机飞行的代码,主要有两种,你们看需要自取。
第一种,通过判断所按键盘的按钮来判断飞机操作有哪些,主要放了上下左右移动。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class move : MonoBehaviour
{
public float speed = 1.5f;//控制移动速度
public Transform m_transform;
void Start()
{
m_transform = this.transform;
}
// Time.deltaTime 为每一帧的时间,为固定值。
void Update()
{
if (Input.GetKey(KeyCode.A))
{
m_transform.Translate(Vector3.left * Time.deltaTime * speed);
}
if (Input.GetKey(KeyCode.W))
{
m_transform.Translate(Vector3.forward