using UnityEngine;
|
|
using System.Collections;
|
|
|
|
public class Thruster : MonoBehaviour {
|
|
|
|
public float speed;
|
|
public float thrustDuration;
|
|
|
|
public bool shot = false;
|
|
public bool attached = false;
|
|
|
|
private ParticleSystem particles;
|
|
|
|
[HideInInspector]
|
|
public Rigidbody2D rigid;
|
|
// Use this for initialization
|
|
void Start () {
|
|
rigid = GetComponent<Rigidbody2D>();
|
|
particles = GetComponentInChildren<ParticleSystem>();
|
|
|
|
particles.enableEmission = false;
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void FixedUpdate () {
|
|
if (Input.anyKeyDown && attached) {
|
|
StartCoroutine(fireEngines());
|
|
}
|
|
|
|
/*
|
|
rigid.AddForceAtPosition(transform.right * speed, transform.position, ForceMode2D.Impulse);
|
|
particles.enableEmission = true;
|
|
shot = true;
|
|
|
|
} else if (shot) {
|
|
|
|
Destroy(gameObject);
|
|
} else {
|
|
particles.enableEmission = false;
|
|
}
|
|
*/
|
|
|
|
|
|
}
|
|
|
|
private IEnumerator fireEngines() {
|
|
Debug.Log("firing Engines");
|
|
float startTime = Time.time;
|
|
particles.enableEmission = true;
|
|
|
|
while (Time.time - startTime < thrustDuration) {
|
|
rigid.AddForceAtPosition(transform.right * speed, transform.position, ForceMode2D.Impulse);
|
|
yield return new WaitForSeconds(0.01f);
|
|
}
|
|
|
|
Destroy(gameObject);
|
|
yield return null;
|
|
|
|
}
|
|
}
|