using UnityEngine; using Saltosion.OneWeapon.Player; using Saltosion.OneWeapon.Enemies; using Saltosion.OneWeapon.Effects; namespace Saltosion.OneWeapon.Guns { [RequireComponent(typeof(Bullet))] public class MobcatBullet : MonoBehaviour { public Rigidbody2D Body; public GameObject Sprite; public ParticleSystem Trail; public ParticleSystem Explosion; [Tooltip("This currently does not affect the Fun damage.")] public float Damage = 12; private float DeathTimer = 0; private Bullet Bullet; void Start() { Bullet = GetComponent(); Vector2 Direction = Bullet.Direction; float Rot = Bullet.InitialRotation; Body.velocity = Direction * 15; Body.rotation = Rot - 90; Explosion.Stop(); } void Update() { DeathTimer += Time.deltaTime; if (DeathTimer > 20) { Destroy(gameObject); } } void OnTriggerEnter2D(Collider2D collider) { Bullet.HasExploded = true; Destroy(Sprite); Destroy(Body); Destroy(GetComponent()); Explosion.Play(); Trail.Stop(); DeathTimer = 19; // Do damage here, kill everyone PlayerFun Player = collider.GetComponent(); Health OtherEnemyHealth = collider.GetComponent(); if (Player != null) { Player.TakeDamage(); } if (OtherEnemyHealth != null) { OtherEnemyHealth.Damage(Damage, Bullet.Direction, false); } if (collider.tag == "Environment") { DebrisLauncher.Splatter(DebrisType.Structural, transform.position, Bullet.Direction, 5, 30, 360); } if (collider.attachedRigidbody != null && collider.attachedRigidbody.bodyType == RigidbodyType2D.Dynamic) { collider.attachedRigidbody.AddForce(Bullet.Direction * 4, ForceMode2D.Impulse); } } } }