MiniGames/Assets/Scripts/ChaseOn/ChasePowerUp.cs

42 lines
1.2 KiB
C#

using System.Collections;
using UnityEngine;
public class ChasePowerUp : MonoBehaviour
{
public float speedBoostAmount = 3f; // How much to boost the speed
public float duration = 5f; // Duration of the speed boost
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
ChasePlayerController player = other.GetComponent<ChasePlayerController>();
if (player != null)
{
StartCoroutine(ApplySpeedBoost(player));
}
// Optionally destroy the power-up after pickup
Destroy(gameObject);
}
}
private IEnumerator ApplySpeedBoost(ChasePlayerController player)
{
float originalSpeed = player.moveSpeed;
float boostedSpeed = originalSpeed + speedBoostAmount;
player.SetMoveSpeed(boostedSpeed);
Debug.Log("Speed Boost Activated!");
yield return new WaitForSeconds(duration);
// Only revert if the player's current speed is still the boosted speed
if (player.moveSpeed == boostedSpeed)
{
player.SetMoveSpeed(originalSpeed);
Debug.Log("Speed Boost Ended");
}
}
}