Advertisement
Guest User

unity problem .2

a guest
Feb 20th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3.  
  4. public class ROCKET : MonoBehaviour
  5.  
  6. {
  7.  
  8. AudioSource AS;
  9. AudioClip AC;
  10. Rigidbody RB;
  11.  
  12.  
  13. public AudioClip Explosion;
  14.  
  15.  
  16.  
  17. public float RotationThrust = 1000f;
  18. public float UpThrust = 1000f;
  19.  
  20. public ParticleSystem Thrust;
  21. public ParticleSystem Fail;
  22. public ParticleSystem Win;
  23.  
  24. enum PlayerSituation {Alive,Died,Win };
  25.  
  26. PlayerSituation Situation;
  27.  
  28. void Start()
  29. {
  30.  
  31.  
  32. RB = GetComponent<Rigidbody>();
  33. AS = GetComponent<AudioSource>();
  34.  
  35.  
  36.  
  37. }
  38. // Update is called once per frame
  39.  
  40. void Update() // action qui doit se faire chaque secondes//
  41.  
  42. {
  43.  
  44.  
  45. if (Situation == PlayerSituation.Alive)
  46. {
  47.  
  48. Up();
  49. Rotate();
  50. }
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66. }
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76. private void OnCollisionEnter(Collision collision)
  77. {
  78. if (Situation!=PlayerSituation.Alive)
  79. {
  80. return; // remove the other collision after the death//not for the rocket
  81.  
  82.  
  83.  
  84. }
  85.  
  86. switch (collision.gameObject.tag)
  87. {
  88.  
  89.  
  90. case "DANGER!":
  91. Situation = PlayerSituation.Died;
  92. Thrust.Stop();
  93. Fail.Emit(10000);
  94. AS.Stop();
  95. AS.PlayOneShot(Explosion);
  96. break;
  97.  
  98. case "WIN":
  99.  
  100. Debug.Log(collision.gameObject.tag);
  101. Win.Play();
  102.  
  103.  
  104. break;
  105.  
  106. }
  107.  
  108.  
  109.  
  110. }
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120. void Up() // propulsion of rocket//
  121. {
  122.  
  123.  
  124. float upPlus = UpThrust * Time.deltaTime; // add more propulsion//
  125.  
  126.  
  127. if (Input.GetKey(KeyCode.W)) // my rocket doesn't want to work ---> maybe this is the problem
  128. {
  129. RB.AddRelativeForce(Vector3.up * upPlus);
  130.  
  131.  
  132. if (!AS.isPlaying)
  133. {
  134.  
  135. AS.Play();
  136.  
  137.  
  138. }
  139.  
  140. Thrust.Play();
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148. }
  149.  
  150. else
  151. {
  152.  
  153. Thrust.Stop();
  154. AS.Stop();
  155.  
  156. }
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163. }
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181. void Rotate() //rotation of the rocket//
  182. {
  183. float rotationPlus = RotationThrust * Time.deltaTime;
  184.  
  185.  
  186. RB.freezeRotation = true;
  187. if (Input.GetKey(KeyCode.A))
  188. {
  189. transform.Rotate(transform.forward * rotationPlus);
  190.  
  191.  
  192.  
  193. }
  194.  
  195. else if (Input.GetKey(KeyCode.D))
  196. {
  197.  
  198.  
  199. transform.Rotate(-transform.forward * rotationPlus);
  200.  
  201.  
  202.  
  203.  
  204. }
  205. RB.freezeRotation = false;
  206.  
  207.  
  208.  
  209.  
  210.  
  211. }
  212.  
  213.  
  214.  
  215. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement