Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Rocket : MonoBehaviour
- {
- public float TimeToIgnite = 1f;
- public float FireTime = 3f;
- public float Power = 1f;
- public bool isFiring = false;
- private float timeLeftToIgnite = 0f;
- private float timeLeftForBurn = 0f;
- private void Start()
- {
- timeLeftToIgnite = TimeToIgnite;
- timeLeftForBurn = FireTime;
- }
- void FixedUpdate()
- {
- if(timeLeftToIgnite <= 0)
- isFiring = true;
- else
- timeLeftToIgnite -= Time.fixedDeltaTime;
- if(isFiring && timeLeftForBurn > 0)
- {
- this.GetComponent<Rigidbody>().AddForce(this.GetComponent<Transform>().up * (Power * 10));
- timeLeftForBurn -= Time.fixedDeltaTime;
- }
- if (timeLeftForBurn <= 0)
- isFiring = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment