Guest User

Untitled

a guest
Jun 3rd, 2017
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Rocket : MonoBehaviour
  6. {
  7.  
  8. public float TimeToIgnite = 1f;
  9. public float FireTime = 3f;
  10. public float Power = 1f;
  11. public bool isFiring = false;
  12. private float timeLeftToIgnite = 0f;
  13. private float timeLeftForBurn = 0f;
  14.  
  15. private void Start()
  16. {
  17. timeLeftToIgnite = TimeToIgnite;
  18. timeLeftForBurn = FireTime;
  19. }
  20. void FixedUpdate()
  21. {
  22.  
  23. if(timeLeftToIgnite <= 0)
  24. isFiring = true;
  25. else
  26. timeLeftToIgnite -= Time.fixedDeltaTime;
  27.  
  28. if(isFiring && timeLeftForBurn > 0)
  29. {
  30. this.GetComponent<Rigidbody>().AddForce(this.GetComponent<Transform>().up * (Power * 10));
  31. timeLeftForBurn -= Time.fixedDeltaTime;
  32. }
  33. if (timeLeftForBurn <= 0)
  34. isFiring = false;
  35.  
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment