Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Rocket : MonoBehaviour
- {
- Rigidbody rigidBody;
- AudioSource thrusters;
- bool thrustersPlay;
- // Start is called before the first frame update
- void Start()
- {
- thrusters = GetComponent<AudioSource>();
- rigidBody = GetComponent<Rigidbody>();
- thrustersPlay = false;
- }
- // Update is called once per frame
- void Update()
- {
- Thrusters();
- Rotation();
- }
- void Thrusters()
- {
- if (Input.GetKey(KeyCode.Space)) //Can thrust while rotating
- {
- rigidBody.AddRelativeForce(Vector3.up);
- if (!thrusters.isPlaying) //plays only once
- {
- thrusters.Play();
- }
- }
- else
- {
- thrusters.Stop();
- }
- }
- void Rotation()
- {
- if (Input.GetKey(KeyCode.A)) // Rotating left
- {
- transform.Rotate(Vector3.forward);
- }
- else if (Input.GetKey(KeyCode.D)) //Rotating right
- {
- transform.Rotate(-Vector3.forward);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement