Hi I am a beginner in Unity especially in AR, and currently doing a project about putting out fire (particle system) with fire extinguisher (water which is particle system too). I don’t know how to collide both of the particle system and put out the fire using water particle system. I have a script that will extinguish the fire but it does not work. Can someone help me ASAP?
This is extinguisher script
public class extinguisherScript : MonoBehaviour
{
[SerializeField] private float amountExtiPSec = 1.0f;
[SerializeField] private Transform raycastOrigin = null;
private bool IsRaycastingSomething(out RaycastHit hit) => Physics.Raycast(raycastOrigin.position, raycastOrigin.forward, out hit, 100f);
private bool IsRaycastingFire(out fireScript fire) {
fire = null;
return IsRaycastingSomething(out RaycastHit hit) && hit.collider.TryGetComponent(out fire); }
private void Update() {
if (IsRaycastingFire(out fireScript fire))
ExtinguishFire(fire); }
private void ExtinguishFire(fireScript fire)
{ fire.TryExtinguish(amountExtiPSec * Time.deltaTime); }
}
and this is my fire script
public class fireScript : MonoBehaviour
{
public GameObject panel;
[SerializeField, Range(0f, 1f)]
private float currentIntensity = 1.0f;
public float GetIntensity() => currentIntensity;
private float[] startIntensity = new float[0];
float nextRegenTime = 0;
[SerializeField] float regenDelay = 2.5f;
[SerializeField] private float regenRate = .1f;
[SerializeField] private ParticleSystem[] fireParticleSystem = new ParticleSystem[0];
private bool isLit = true;
private void Start()
{
startIntensity = new float[fireParticleSystem.Length];
for (int i=0;i<fireParticleSystem.Length;i++)
{
startIntensity[i] = fireParticleSystem[i].emission.rateOverTime.constant;
}
}
private void Update()
{
if (isLit && currentIntensity<1.0f)
{
Regenerate();
}
}
private void Regenerate()
{
if (Time.time < nextRegenTime)
return;
currentIntensity += regenRate * Time.deltaTime;
ChangeIntensity();
}
public bool TryExtinguish(float amount)
{
nextRegenTime = Time.time +regenDelay;
currentIntensity -= amount;
ChangeIntensity();
if (currentIntensity<=0)
{
Die();
panel.gameObject.SetActive(true);
return true;
}
return false; //fire still lit
}
private void Die()
{
isLit = false;
enabled = false;
}
private void ChangeIntensity()
{
for (int i = 0; i < fireParticleSystem.Length; i++)
{
var emission = fireParticleSystem[i].emission;
emission.rateOverTime = currentIntensity * startIntensity[i];
}
}
}