Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- public class ROCKET : MonoBehaviour
- {
- AudioSource AS;
- AudioClip AC;
- Rigidbody RB;
- public AudioClip Explosion;
- public float RotationThrust = 1000f;
- public float UpThrust = 1000f;
- public ParticleSystem Thrust;
- public ParticleSystem Fail;
- public ParticleSystem Win;
- enum PlayerSituation {Alive,Died,Win };
- PlayerSituation Situation;
- void Start()
- {
- RB = GetComponent<Rigidbody>();
- AS = GetComponent<AudioSource>();
- }
- // Update is called once per frame
- void Update() // action qui doit se faire chaque secondes//
- {
- if (Situation == PlayerSituation.Alive)
- {
- Up();
- Rotate();
- }
- }
- private void OnCollisionEnter(Collision collision)
- {
- if (Situation!=PlayerSituation.Alive)
- {
- return; // remove the other collision after the death//not for the rocket
- }
- switch (collision.gameObject.tag)
- {
- case "DANGER!":
- Situation = PlayerSituation.Died;
- Thrust.Stop();
- Fail.Emit(10000);
- AS.Stop();
- AS.PlayOneShot(Explosion);
- break;
- case "WIN":
- Debug.Log(collision.gameObject.tag);
- Win.Play();
- break;
- }
- }
- void Up() // propulsion of rocket//
- {
- float upPlus = UpThrust * Time.deltaTime; // add more propulsion//
- if (Input.GetKey(KeyCode.W)) // my rocket doesn't want to work ---> maybe this is the problem
- {
- RB.AddRelativeForce(Vector3.up * upPlus);
- if (!AS.isPlaying)
- {
- AS.Play();
- }
- Thrust.Play();
- }
- else
- {
- Thrust.Stop();
- AS.Stop();
- }
- }
- void Rotate() //rotation of the rocket//
- {
- float rotationPlus = RotationThrust * Time.deltaTime;
- RB.freezeRotation = true;
- if (Input.GetKey(KeyCode.A))
- {
- transform.Rotate(transform.forward * rotationPlus);
- }
- else if (Input.GetKey(KeyCode.D))
- {
- transform.Rotate(-transform.forward * rotationPlus);
- }
- RB.freezeRotation = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement