BloodAndGore/Assets/Scripts/Guns/MobcatBullet.cs

77 lines
2.4 KiB
C#
Raw Normal View History

2019-08-18 23:26:42 +02:00
using UnityEngine;
2019-08-18 20:32:07 +02:00
using Saltosion.OneWeapon.Player;
using Saltosion.OneWeapon.Enemies;
using Saltosion.OneWeapon.Effects;
namespace Saltosion.OneWeapon.Guns {
2019-08-21 23:11:10 +02:00
[RequireComponent(typeof(Bullet), typeof(CustomLight))]
2019-08-18 23:26:42 +02:00
public class MobcatBullet : MonoBehaviour {
2019-08-18 20:32:07 +02:00
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;
2019-08-21 23:11:10 +02:00
private CustomLight Light;
2019-08-18 20:32:07 +02:00
void Start() {
Bullet = GetComponent<Bullet>();
2019-08-21 23:11:10 +02:00
Light = GetComponent<CustomLight>();
2019-08-18 20:32:07 +02:00
Vector2 Direction = Bullet.Direction;
float Rot = Bullet.InitialRotation;
2019-08-21 23:11:10 +02:00
Light.LightIntensity = 1.1f;
2019-08-18 20:32:07 +02:00
Body.velocity = Direction * 15;
Body.rotation = Rot - 90;
Explosion.Stop();
}
void Update() {
DeathTimer += Time.deltaTime;
if (DeathTimer > 20) {
Destroy(gameObject);
}
2019-08-21 23:11:10 +02:00
if (DeathTimer > 19) {
Light.LightIntensity = Mathf.Max(2 - (DeathTimer - 19f) * 10, 0);
}
2019-08-18 20:32:07 +02:00
}
void OnTriggerEnter2D(Collider2D collider) {
Bullet.HasExploded = true;
Destroy(Sprite);
Destroy(Body);
Destroy(GetComponent<CapsuleCollider2D>());
2019-08-21 23:11:10 +02:00
Light.LightSize = 4;
2019-08-18 20:32:07 +02:00
Explosion.Play();
Trail.Stop();
DeathTimer = 19;
// Do damage here, kill everyone
PlayerFun Player = collider.GetComponent<PlayerFun>();
Health OtherEnemyHealth = collider.GetComponent<Health>();
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);
}
}
}
}