BloodAndGore/Assets/Scripts/Effects/BloodDripper.cs

39 lines
1.5 KiB
C#
Raw Normal View History

2019-08-07 21:48:34 +02:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
2019-08-14 16:17:48 +02:00
namespace Saltosion.OneWeapon.Effects {
2019-08-07 21:48:34 +02:00
public class BloodDripper : MonoBehaviour {
public Vector2 DripOffset = new Vector2(0, -0.5f);
public int DripCount = 5;
public float DropInterval = 0.5f;
private Rigidbody2D ParentBody;
private int Drips = 0;
private bool Step = false;
private float LastDropTime;
private void Start() {
ParentBody = transform.parent.GetComponent<Rigidbody2D>();
DropInterval *= Random.value + 0.5f;
LastDropTime = Random.value * DropInterval + Time.time;
}
private void Update() {
if (ParentBody.velocity.magnitude > 0.1 && Time.time - LastDropTime > DropInterval) {
Step = !Step;
bool WalkingSideWays = Mathf.Abs(Vector2.Dot(ParentBody.velocity, new Vector2(1, 0))) > 0.5;
Vector2 Offset = DripOffset + new Vector2(-ParentBody.velocity.y, ParentBody.velocity.x).normalized *
(WalkingSideWays ? 0.1f : 0.2f) *
(Step ? 1f : -1f);
2019-08-14 23:27:14 +02:00
DebrisLauncher.Splatter(DebrisType.Blood, ParentBody.position + Offset, Vector2.zero, 1 + (int)(Random.value * 5), 0f, 360f, false);
2019-08-07 21:48:34 +02:00
Drips++;
if (Drips >= DripCount) {
Destroy(gameObject);
}
LastDropTime = Time.time;
}
}
}
}