Here is my code
using UnityEngine;
using UnityEngine.SceneManagement;
public class movement : MonoBehaviour
{
Rigidbody rb;
AudioSource MaudioSoure;
public float thrust;
public float Rotation;
void Start()
{
rb = GetComponent<Rigidbody>();
MaudioSoure = GetComponent<AudioSource>();
}
void Update()
{
if (Input.GetKey(KeyCode.Space))
{
rb.AddRelativeForce(Vector3.up * thrust * Time.deltaTime);
if(!MaudioSoure.isPlaying)
{
MaudioSoure.Play();
}
}
else
{
MaudioSoure.Stop();
}
if (Input.GetKey(KeyCode.D))
{
rb.freezeRotation = true;
ApplyRotation(-Rotation);
}
else if (Input.GetKey(KeyCode.A))
{
rb.freezeRotation = true;
ApplyRotation(Rotation);
}
else
{
rb.freezeRotation = false;
rb.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotationY;
}
}
void ApplyRotation(float direction)
{
transform.Rotate(0, 0, direction * Time.deltaTime);
}
}