using UnityEngine; public class SlowdownArea : MonoBehaviour { [Header("References")] public float maxSlow; public float slowSpeed; public float timer; public GameObject playerBody; [Header("Root Crawler")] public GameObject rootCrawlerPrefab; private float baseJump; private bool isInZone = false; private PlayerMovement player; private PlayerJump jump; private GameObject currentCrawler; private void OnTriggerEnter(Collider area) { if (area.CompareTag("Player")){ player = area.GetComponent(); jump = area.GetComponent(); baseJump = 5.0f; jump.JumpForce = 1.5f; isInZone = true; if (currentCrawler == null) { currentCrawler = Instantiate(rootCrawlerPrefab, player.transform); RootCrawler crawler = currentCrawler.GetComponent(); crawler.target = playerBody.transform; } } } private void OnTriggerExit(Collider area) { if (area.CompareTag("Player")) { isInZone = false; timer = 0f; player.ApplySlow(1f); player.ApplyAnimationSlow(1f); jump.JumpForce = baseJump; if (currentCrawler != null) { Destroy(currentCrawler); } } } // Update is called once per frame void Update() { if (!isInZone || player == null) return; timer += Time.deltaTime; float t = Mathf.Clamp(timer * slowSpeed, 0f, 1f); float multiplicator = Mathf.Lerp(1f, maxSlow, t); player.ApplySlow(multiplicator); player.ApplyAnimationSlow(multiplicator); } }