using System.Collections; using System.Collections.Generic; using UnityEngine; using Saltosion.OneWeapon.Player; using Saltosion.OneWeapon.Enemies; using Saltosion.OneWeapon.Effects; using Saltosion.OneWeapon.Environment; namespace Saltosion.OneWeapon.Guns { [RequireComponent(typeof(Bullet))] public class RevolverBullet : MonoBehaviour { public Rigidbody2D Body; public GameObject Sprite; public ParticleSystem Trail; public ParticleSystem Explosion; private float DeathTimer = 0; void Start() { Vector2 Direction = GetComponent().Direction; float Rot = GetComponent().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) { if (collider.GetComponent() != null) { // don't hit the player! return; } Destroy(Sprite); Destroy(Body); Destroy(GetComponent()); Explosion.Play(); Trail.Stop(); DeathTimer = 19; // Do damage here, kill everyone Explodable Explodable = collider.GetComponent(); Health Health = collider.GetComponent(); VendingMachine VendingMachine = collider.GetComponent(); Vector2 Direction = (collider.transform.position - transform.position).normalized; if (Health != null) { Health.Damage(12f, -Direction, true); } else if (VendingMachine != null) { VendingMachine.ExpelGun(); } else if (Explodable != null) { Explodable.Explode(true); } else if (collider.tag == "Environment") { BloodLauncher.DebrisExplode(transform.position, Body.velocity.normalized * 0.7f, 5, 30f, 360); } if (collider.attachedRigidbody != null && collider.attachedRigidbody.bodyType == RigidbodyType2D.Dynamic) { collider.attachedRigidbody.AddForce(Direction * 4f, ForceMode2D.Impulse); } } } }