Guest User

Untitled

a guest
Jun 3rd, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 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. public GameObject target;
  15. public bool doTarget = false;
  16.  
  17. private void Start()
  18. {
  19. timeLeftToIgnite = TimeToIgnite;
  20. timeLeftForBurn = FireTime;
  21. }
  22. void FixedUpdate()
  23. {
  24. if(doTarget)
  25. {
  26. this.transform.LookAt(target.transform);
  27. }
  28. if(timeLeftToIgnite <= 0)
  29. isFiring = true;
  30. else
  31. timeLeftToIgnite -= Time.fixedDeltaTime;
  32.  
  33. if(isFiring && timeLeftForBurn > 0)
  34. {
  35. this.GetComponent<Rigidbody>().AddForce(this.GetComponent<Transform>().up * (Power * 10));
  36. timeLeftForBurn -= Time.fixedDeltaTime;
  37. }
  38. if (timeLeftForBurn <= 0)
  39. isFiring = false;
  40.  
  41. }
  42. public void SetTarget(GameObject target1)
  43. {
  44. target = target1;
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment