using UnityEngine; // Designed by Jacob Weedman // Attach to the rocket weapon prefab public class EnemyRocket : MonoBehaviour { public float duration; public int WeaponDamage; void FixedUpdate() { if (duration <= 0) { GetComponent().gravityScale = 3; } else { GetComponent().gravityScale = 0; } duration -= Time.deltaTime; } void Explode() { //Create Explosion GameObject Explosion; Explosion = Instantiate(GameObject.Find("Explosion"), new Vector3(transform.position.x, transform.position.y, GameObject.Find("Explosion").transform.position.z), Quaternion.identity); Explosion.transform.rotation = Quaternion.Euler(Vector3.forward); //Set Variables Explosion.GetComponent().timer = 3; Explosion.GetComponent().destroy = true; Explosion.GetComponent().opacity = true; Explosion.GetComponent().damageAmmount = WeaponDamage; //Delete Rocket Destroy(gameObject); } void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.tag == "Ground") { if (collision.gameObject.layer == 6) { Explode(); } } if (collision.gameObject.tag == "Player") { Explode(); } } }