2019-08-04 00:59:18 +02:00
|
|
|
|
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-04 00:59:18 +02:00
|
|
|
|
|
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 {
|
2019-08-04 00:59:18 +02:00
|
|
|
|
|
|
|
|
|
public Rigidbody2D Body;
|
2019-08-04 01:45:55 +02:00
|
|
|
|
public GameObject Sprite;
|
|
|
|
|
|
|
|
|
|
public ParticleSystem Trail;
|
|
|
|
|
public ParticleSystem Explosion;
|
|
|
|
|
|
2019-08-18 19:44:12 +02:00
|
|
|
|
public float Damage = 12;
|
|
|
|
|
|
2019-08-04 01:45:55 +02:00
|
|
|
|
private float DeathTimer = 0;
|
2019-08-04 00:59:18 +02:00
|
|
|
|
|
2019-08-14 23:58:24 +02:00
|
|
|
|
private Bullet Bullet;
|
2019-08-21 23:11:10 +02:00
|
|
|
|
private CustomLight Light;
|
2019-08-14 23:58:24 +02:00
|
|
|
|
|
2019-08-04 00:59:18 +02:00
|
|
|
|
void Start() {
|
2019-08-14 23:58:24 +02:00
|
|
|
|
Bullet = GetComponent<Bullet>();
|
2019-08-21 23:11:10 +02:00
|
|
|
|
Light = GetComponent<CustomLight>();
|
2019-08-14 23:58:24 +02:00
|
|
|
|
Vector2 Direction = Bullet.Direction;
|
|
|
|
|
float Rot = Bullet.InitialRotation;
|
2019-08-04 00:59:18 +02:00
|
|
|
|
|
2019-08-21 23:11:10 +02:00
|
|
|
|
Light.LightIntensity = 1.1f;
|
|
|
|
|
|
2019-08-04 00:59:18 +02:00
|
|
|
|
Body.velocity = Direction * 15;
|
|
|
|
|
Body.rotation = Rot - 90;
|
2019-08-04 01:45:55 +02:00
|
|
|
|
|
|
|
|
|
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-04 00:59:18 +02:00
|
|
|
|
}
|
2019-08-04 01:10:18 +02:00
|
|
|
|
|
|
|
|
|
void OnTriggerEnter2D(Collider2D collider) {
|
2019-08-14 16:17:48 +02:00
|
|
|
|
if (collider.GetComponent<PlayerController>() != null) {
|
2019-08-04 01:10:18 +02:00
|
|
|
|
// don't hit the player!
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-08-14 23:58:24 +02:00
|
|
|
|
Bullet.HasExploded = true;
|
|
|
|
|
|
2019-08-04 01:45:55 +02:00
|
|
|
|
Destroy(Sprite);
|
|
|
|
|
Destroy(Body);
|
|
|
|
|
Destroy(GetComponent<CapsuleCollider2D>());
|
2019-08-21 23:11:10 +02:00
|
|
|
|
Light.LightSize = 4;
|
2019-08-04 01:45:55 +02:00
|
|
|
|
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);
|
2019-08-04 01:10:18 +02:00
|
|
|
|
}
|
2019-08-04 00:59:18 +02:00
|
|
|
|
}
|
|
|
|
|
}
|