|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using Unity.BossRoom.Gameplay.GameplayObjects.Character;
|
|
|
|
using Unity.Netcode;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.AI;
|
|
|
|
|
|
|
|
public class SlowZonePrefab : NetworkBehaviour
|
|
|
|
{
|
|
|
|
[Header("Slow Zone Settings")]
|
|
|
|
public float zoneRadius = 5f; // Radius of the slow zone
|
|
|
|
public float slowDuration = 3f; // Duration of the slow effect
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
{
|
|
|
|
// Start the process to slow down players when the zone is spawned
|
|
|
|
StartCoroutine(ApplySlowEffect());
|
|
|
|
}
|
|
|
|
|
|
|
|
private IEnumerator ApplySlowEffect()
|
|
|
|
{
|
|
|
|
// Run the logic once immediately
|
|
|
|
ApplySlowToPlayers();
|
|
|
|
|
|
|
|
// Optionally, repeat the check while the zone exists
|
|
|
|
yield return new WaitForSeconds(slowDuration);
|
|
|
|
|
|
|
|
// Destroy the zone after applying the slow effect
|
|
|
|
Destroy(gameObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ApplySlowToPlayers()
|
|
|
|
{
|
|
|
|
// Find all colliders in the zone
|
|
|
|
Collider[] hitColliders = Physics.OverlapSphere(transform.position, zoneRadius);
|
|
|
|
foreach (var collider in hitColliders)
|
|
|
|
{
|
|
|
|
if (collider.TryGetComponent<ServerCharacter>(out var player))
|
|
|
|
{
|
|
|
|
// Check if the player is NOT the crow
|
|
|
|
if (!player.IsCrow)
|
|
|
|
{
|
|
|
|
// Apply slow effect
|
|
|
|
StartCoroutine(SlowPlayer(player));
|
|
|
|
Debug.Log($"{player.name} is slowed down!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private IEnumerator SlowPlayer(ServerCharacter player)
|
|
|
|
{
|
|
|
|
// Halve the player's movement speed
|
|
|
|
player.Movement.SetSpeedModifier(0.2f);
|
|
|
|
// player.Movement.SetMovementSpeed(originalSpeed * slowMultiplier);
|
|
|
|
|
|
|
|
// Wait for the slow duration
|
|
|
|
yield return new WaitForSeconds(slowDuration);
|
|
|
|
|
|
|
|
// Restore the original speed
|
|
|
|
player.Movement.ResetSpeedModifier();
|
|
|
|
Debug.Log($"{player.name}'s speed is restored.");
|
|
|
|
Destroy(gameObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Debug visualization for the slow zone in the editor
|
|
|
|
private void OnDrawGizmos()
|
|
|
|
{
|
|
|
|
Gizmos.color = Color.cyan;
|
|
|
|
Gizmos.DrawWireSphere(transform.position, zoneRadius);
|
|
|
|
}
|
|
|
|
}
|