using UnityEngine; public class SpawnDeformation : MonoBehaviour { public static float TimeBtwnEachDeformation = 0.5f; public float thresholdSpeed = 0.75f; public float maxSpeed = 5f; public float deformationAmplitudeMultipler = 0.1f; private float lastDeformationSpawnedTime; private Vector3 lastPosition = Vector3.zero; private void Update() { Vector3 vector = (base.transform.position - lastPosition) / Time.deltaTime; float normalizedHeightOfSphereBelowSurface = GetComponent().GetNormalizedHeightOfSphereBelowSurface(); if (vector.magnitude > thresholdSpeed && normalizedHeightOfSphereBelowSurface > 0f && normalizedHeightOfSphereBelowSurface < 1f && Time.realtimeSinceStartup - lastDeformationSpawnedTime >= TimeBtwnEachDeformation && PoolManager.Instances[PoolManager.InstanceType.Deformer] != null) { GameObject nextAvailable = PoolManager.Instances[PoolManager.InstanceType.Deformer].getNextAvailable(); if (nextAvailable != null) { lastDeformationSpawnedTime = Time.realtimeSinceStartup; nextAvailable.transform.position = base.transform.position + base.transform.forward * vector.magnitude * 0.01f; float num = Mathf.InverseLerp(thresholdSpeed, maxSpeed, vector.magnitude); nextAvailable.GetComponent().SetAmplitude(num * deformationAmplitudeMultipler); nextAvailable.SetActive(value: true); } } lastPosition = base.transform.position; } }