BloodAndGore/Assets/Scripts/Guns/RegularBullet.cs

71 lines
1.9 KiB
C#
Raw Permalink Normal View History

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
2019-08-14 16:17:48 +02:00
using Saltosion.OneWeapon.Player;
using Saltosion.OneWeapon.Enemies;
using Saltosion.OneWeapon.Effects;
2019-08-14 19:05:16 +02:00
using Saltosion.OneWeapon.Environment;
2019-08-14 16:17:48 +02:00
namespace Saltosion.OneWeapon.Guns {
2019-08-21 23:11:10 +02:00
[RequireComponent(typeof(Bullet), typeof(CustomLight))]
2019-08-18 19:44:12 +02:00
public class RegularBullet : MonoBehaviour {
public Rigidbody2D Body;
public GameObject Sprite;
public ParticleSystem Trail;
public ParticleSystem Explosion;
2019-08-18 19:44:12 +02:00
public float Damage = 12;
2019-08-22 19:13:49 +02:00
public float Speed = 15;
2019-08-18 19:44:12 +02:00
private float DeathTimer = 0;
private Bullet Bullet;
2019-08-21 23:11:10 +02:00
private CustomLight Light;
void Start() {
Bullet = GetComponent<Bullet>();
2019-08-21 23:11:10 +02:00
Light = GetComponent<CustomLight>();
Vector2 Direction = Bullet.Direction;
float Rot = Bullet.InitialRotation;
2019-08-21 23:11:10 +02:00
Light.LightIntensity = 1.1f;
2019-08-22 19:13:49 +02:00
Body.velocity = Direction * Speed;
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);
}
}
void OnTriggerEnter2D(Collider2D collider) {
2019-08-14 16:17:48 +02:00
if (collider.GetComponent<PlayerController>() != null) {
// don't hit the player!
return;
}
Bullet.HasExploded = true;
Destroy(Sprite);
Destroy(Body);
Destroy(GetComponent<CapsuleCollider2D>());
2019-08-21 23:11:10 +02:00
Light.LightSize = 4;
Explosion.Play();
Trail.Stop();
DeathTimer = 19;
// Do damage here, kill everyone
2019-08-18 19:44:12 +02:00
Bullet.DoDamage(Damage, 1, collider, Bullet.Direction);
}
}
}