Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Rocket : MonoBehaviour
- {
- Rigidbody rigidBody;
- AudioSource audioSource;
- bool thrustersPlay;
- // Start is called before the first frame update
- void Start()
- {
- audioSource = 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
- {
- print("Thrusting");
- rigidBody.AddRelativeForce(Vector3.up);
- if (!audioSource.isPlaying) //plays only once
- {
- audioSource.Play();
- }
- }
- else
- {
- audioSource.Stop();
- }
- }
- void Rotation()
- {
- rigidBody.freezeRotation = true; //take manual control of rotation
- if (Input.GetKey(KeyCode.A)) // Rotating left
- {
- transform.Rotate(Vector3.forward);
- }
- else if (Input.GetKey(KeyCode.D)) //Rotating right
- {
- transform.Rotate(-Vector3.forward);
- }
- rigidBody.freezeRotation = false; //resume physics control of rotation
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement