Advertisement
Guest User

Untitled

a guest
Jul 11th, 2019
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.11 KB | None | 0 0
  1. public class Rocket : MonoBehaviour
  2. {
  3.     Rigidbody rigidBody;
  4.     AudioSource thrusters;
  5.  
  6.     bool thrustersPlay;
  7.  
  8.  
  9.     // Start is called before the first frame update
  10.     void Start()
  11.     {
  12.         thrusters = GetComponent<AudioSource>();
  13.         rigidBody = GetComponent<Rigidbody>();
  14.         thrustersPlay = false;
  15.     }
  16.  
  17.     // Update is called once per frame
  18.     void Update()
  19.     {
  20.         Thrusters();
  21.         Rotation();
  22.     }
  23.  
  24.     void Thrusters()
  25.     {
  26.         if (Input.GetKey(KeyCode.Space)) //Can thrust while rotating
  27.         {
  28.             rigidBody.AddRelativeForce(Vector3.up);
  29.             if (!thrusters.isPlaying) //plays only once
  30.             {
  31.                 thrusters.Play();
  32.             }
  33.  
  34.         }
  35.         else
  36.         {
  37.             thrusters.Stop();
  38.         }
  39.     }
  40.  
  41.     void Rotation()
  42.     {
  43.        
  44.  
  45.         if (Input.GetKey(KeyCode.A)) // Rotating left
  46.         {
  47.             transform.Rotate(Vector3.forward);
  48.         }
  49.         else if (Input.GetKey(KeyCode.D)) //Rotating right
  50.         {
  51.             transform.Rotate(-Vector3.forward);
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement