51 lines
1.2 KiB
C#
51 lines
1.2 KiB
C#
using UnityEngine;
|
|
|
|
public class SlowdownArea : MonoBehaviour
|
|
{
|
|
|
|
[Header("References")]
|
|
public float maxSlow;
|
|
public float slowSpeed;
|
|
public float timer;
|
|
|
|
|
|
private float baseJump;
|
|
private bool isInZone = false;
|
|
private PlayerMovement player;
|
|
private PlayerJump jump;
|
|
|
|
private void OnTriggerEnter(Collider area)
|
|
{
|
|
if (area.CompareTag("Player")){
|
|
player = area.GetComponent<PlayerMovement>();
|
|
jump = area.GetComponent<PlayerJump>();
|
|
baseJump = 5.0f;
|
|
jump.JumpForce = 1.5f;
|
|
isInZone = true;
|
|
}
|
|
}
|
|
|
|
private void OnTriggerExit(Collider area)
|
|
{
|
|
if (area.CompareTag("Player"))
|
|
{
|
|
isInZone = false;
|
|
timer = 0f;
|
|
player.ApplySlow(1f);
|
|
jump.JumpForce = baseJump;
|
|
}
|
|
}
|
|
|
|
|
|
// 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);
|
|
}
|
|
}
|