BloodAndGore/Assets/Scripts/Guns/Rocket.cs

75 lines
2.0 KiB
C#
Raw Permalink Normal View History

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 {
2019-08-21 23:11:10 +02:00
[RequireComponent(typeof(Bullet), typeof(CustomLight))]
public class Rocket : MonoBehaviour {
public Rigidbody2D Body;
public GameObject Sprite;
public ParticleSystem Trail;
public ParticleSystem Explosion;
[Range(0, 10)]
public float ExplodeRadius;
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;
Body.velocity = Direction * 8;
Body.rotation = Rot - 90;
2019-08-21 23:11:10 +02:00
Light.LightIntensity = 1.1f;
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) {
if (collider.GetComponent<PlayerController>() != null) {
// don't hit the player!
return;
}
Bullet.HasExploded = true;
Destroy(Sprite);
Destroy(Body);
Destroy(GetComponent<CapsuleCollider2D>());
Explosion.Play();
Trail.Stop();
2019-08-21 23:11:10 +02:00
Light.LightSize = 6;
DeathTimer = 19;
2019-08-21 23:11:10 +02:00
Bullet.DoDamageAOE(20, ExplodeRadius, 1.5f);
}
private void OnDrawGizmosSelected() {
Gizmos.color = new Color(1.0f, 0.2f, 0.2f, 0.8f);
Gizmos.DrawWireSphere(transform.position, ExplodeRadius);
}
}
}