Advertisement
jkuehlin

Project Boost Audio Issue

Apr 20th, 2019
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class Rocket : MonoBehaviour {
  4.  
  5. Rigidbody rb;
  6. AudioSource rocket;
  7.  
  8. void Start () {
  9. rb = GetComponent<Rigidbody>();
  10. rocket = GetComponent<AudioSource>();
  11. }
  12.  
  13. void Update()
  14. {
  15. Thrust();
  16. Rotate();
  17. }
  18.  
  19. private void Rotate()
  20. {
  21. rb.freezeRotation = true; //take control of rotation
  22. if (Input.GetKey(KeyCode.A))
  23. {
  24. transform.Rotate(Vector3.forward);
  25. }
  26. else if (Input.GetKey(KeyCode.D))
  27. {
  28. transform.Rotate(Vector3.back);
  29. }
  30. rb.freezeRotation = false; //resume physics control
  31. }
  32.  
  33. private void Thrust()
  34. {
  35. if (Input.GetKey(KeyCode.Space))
  36. {
  37. rb.AddRelativeForce(Vector3.up);
  38. if (!rocket.isPlaying)
  39. {
  40. rocket.Play();
  41. }
  42. }
  43. else if (Input.GetKeyUp(KeyCode.Space))
  44. {
  45. rocket.Stop();
  46. }
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement