36 lines
1.2 KiB
C#
36 lines
1.2 KiB
C#
using UnityEngine;
|
|
using UnityEngine.VFX;
|
|
|
|
public class TriggerSplash : MonoBehaviour
|
|
{
|
|
public GameObject prefab;
|
|
|
|
private float previousNormalizedHeight = -1f;
|
|
|
|
private Rigidbody rigibodyComponent;
|
|
|
|
private void OnEnable()
|
|
{
|
|
rigibodyComponent = GetComponent<Rigidbody>();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
float normalizedHeightOfSphereBelowSurface = GetComponent<Buoyancy>().GetNormalizedHeightOfSphereBelowSurface();
|
|
if (normalizedHeightOfSphereBelowSurface > 0f && previousNormalizedHeight <= 0f && PoolManager.Instances[PoolManager.InstanceType.Splash] != null)
|
|
{
|
|
GameObject nextAvailable = PoolManager.Instances[PoolManager.InstanceType.Splash].getNextAvailable();
|
|
if (nextAvailable != null)
|
|
{
|
|
nextAvailable.transform.position = GetComponent<Buoyancy>().GetCurrentWaterPosition();
|
|
VisualEffect component = nextAvailable.GetComponent<VisualEffect>();
|
|
component.SetFloat("Splash Radius", GetComponent<Buoyancy>().sphereRadiusApproximation);
|
|
component.SetVector3("Velocity", rigibodyComponent.linearVelocity);
|
|
nextAvailable.SetActive(value: true);
|
|
component.Play();
|
|
}
|
|
}
|
|
previousNormalizedHeight = normalizedHeightOfSphereBelowSurface;
|
|
}
|
|
}
|