2019-08-04 00:59:18 +02:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace Saltosion.OneWeapon.Bullets {
|
|
|
|
|
[RequireComponent(typeof(Bullet))]
|
|
|
|
|
public class RevolverBullet : MonoBehaviour {
|
|
|
|
|
|
|
|
|
|
public Rigidbody2D Body;
|
2019-08-04 01:45:55 +02:00
|
|
|
|
public GameObject Sprite;
|
|
|
|
|
|
|
|
|
|
public ParticleSystem Trail;
|
|
|
|
|
public ParticleSystem Explosion;
|
|
|
|
|
|
|
|
|
|
private float DeathTimer = 0;
|
2019-08-04 00:59:18 +02:00
|
|
|
|
|
|
|
|
|
void Start() {
|
|
|
|
|
Vector2 Direction = GetComponent<Bullet>().Direction;
|
|
|
|
|
float Rot = GetComponent<Bullet>().InitialRotation;
|
|
|
|
|
|
|
|
|
|
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-04 00:59:18 +02:00
|
|
|
|
}
|
2019-08-04 01:10:18 +02:00
|
|
|
|
|
|
|
|
|
void OnTriggerEnter2D(Collider2D collider) {
|
|
|
|
|
if (collider.GetComponent<Player>() != null) {
|
|
|
|
|
// don't hit the player!
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-08-04 01:45:55 +02:00
|
|
|
|
Destroy(Sprite);
|
|
|
|
|
Destroy(Body);
|
|
|
|
|
Destroy(GetComponent<CapsuleCollider2D>());
|
|
|
|
|
Explosion.Play();
|
|
|
|
|
Trail.Stop();
|
|
|
|
|
DeathTimer = 19;
|
|
|
|
|
|
|
|
|
|
// Do damage here, kill everyone
|
2019-08-04 02:00:18 +02:00
|
|
|
|
Explodable Explodable = collider.GetComponent<Explodable>();
|
2019-08-07 20:03:51 +02:00
|
|
|
|
Health Health = collider.GetComponent<Health>();
|
2019-08-04 19:08:13 +02:00
|
|
|
|
Vector2 Direction = (collider.transform.position - transform.position).normalized;
|
|
|
|
|
if (Health != null) {
|
2019-08-04 19:48:26 +02:00
|
|
|
|
Health.Damage(12f, -Direction);
|
2019-08-04 19:08:13 +02:00
|
|
|
|
} else if (Explodable != null) {
|
2019-08-04 02:00:18 +02:00
|
|
|
|
Explodable.Explode(true);
|
2019-08-04 17:35:24 +02:00
|
|
|
|
} else if (collider.tag == "Environment") {
|
2019-08-04 16:14:48 +02:00
|
|
|
|
BloodLauncher.DebrisExplode(transform.position, Body.velocity.normalized * 0.7f, 5, 30f, 360);
|
2019-08-04 02:00:18 +02:00
|
|
|
|
}
|
2019-08-04 19:08:13 +02:00
|
|
|
|
if (collider.attachedRigidbody != null && collider.attachedRigidbody.bodyType == RigidbodyType2D.Dynamic) {
|
|
|
|
|
collider.attachedRigidbody.AddForce(Direction * 4f, ForceMode2D.Impulse);
|
|
|
|
|
}
|
2019-08-04 01:10:18 +02:00
|
|
|
|
}
|
2019-08-04 00:59:18 +02:00
|
|
|
|
}
|
|
|
|
|
}
|