using UnityEngine; public class CharacterControllerSpawnDeformation : MonoBehaviour { public static float TimeBtwnEachDeformation = 0.025f; public CharacterController controller; public PlayerMovement playerMovement; private float lastDeformationSpawnedTime; private void Update() { if (IsControllerMoving() && 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 + playerMovement.modelTransform.forward * Vector3.Normalize(controller.velocity).magnitude; nextAvailable.SetActive(value: true); } } } private bool IsControllerMoving() { return controller.velocity.sqrMagnitude > 0f; } }