BloodAndGore/Assets/Scripts/BloodLauncher.cs

33 lines
1.4 KiB
C#
Raw Normal View History

2019-08-03 18:14:47 +02:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Saltosion.OneWeapon {
public class BloodLauncher : MonoBehaviour {
private static BloodLauncher Singleton;
public GameObject BloodParticlePrefab;
public Transform ParticleRoot;
public int MaxParticles;
public bool Launch = false;
public static void Splatter(Vector2 origin, Vector2 direction, int particleCount, float force, float degrees) {
for (int i = 0; i < particleCount; i++) {
if (Singleton.ParticleRoot.childCount >= Singleton.MaxParticles) {
Destroy(Singleton.ParticleRoot.GetChild((int)(Random.value * Singleton.ParticleRoot.childCount)).gameObject);
}
GameObject Obj = Instantiate(Singleton.BloodParticlePrefab, origin, new Quaternion(), Singleton.ParticleRoot);
BloodParticle Particle = Obj.GetComponent<BloodParticle>();
float Intensity = Mathf.Pow(Random.value * force, 1.1f);
float Cone = degrees / 360.0f;
float Offset = Mathf.Atan2(direction.y, direction.x);
float Radians = Offset + Cone * (Random.value - 0.5f) * Mathf.PI * 2.0f;
Particle.LaunchForce = new Vector2(Mathf.Cos(Radians), Mathf.Sin(Radians)) * Intensity;
}
}
private void Start() {
Singleton = this;
}
}
}