using System.Collections; using System.Collections.Generic; using UnityEngine; namespace Saltosion.OneWeapon.Effects { 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(); 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); BloodLauncher.Splatter(ParentBody.position + Offset, Vector2.zero, 1 + (int)(Random.value * 5), 0f, 360f, false); Drips++; if (Drips >= DripCount) { Destroy(gameObject); } LastDropTime = Time.time; } } } }