我该如何让火箭播放器控制器围绕其底部旋转?
以下是我的代码(我知道它有问题,现在只是概念验证):
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Rocket : MonoBehaviour
{
Rigidbody rigidBody;
void Start()
{
rigidBody = GetComponent<Rigidbody>();
}
void Update()
{
ProcessInput();
}
private void ProcessInput()
{
if (Input.GetKey(KeyCode.Space))
{
rigidBody.AddRelativeForce(Vector3.up);
}
if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
{
if (!Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.RightArrow))
{
transform.Rotate(new Vector3(0, 0, 2));
}
}
if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
{
if (!Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.LeftArrow))
{
transform.Rotate(new Vector3(0, 0, -2));
}
}
}
}