You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.6 KiB
C#
48 lines
1.6 KiB
C#
using System.Collections;
|
|
using Unity.BossRoom.Gameplay.GameplayObjects.Character;
|
|
using UnityEngine;
|
|
using Unity.Netcode;
|
|
|
|
[CreateAssetMenu(menuName = "Abilities/DashNCrash")]
|
|
public class DashNCrashAbility : Ability
|
|
{
|
|
[Header("Dash Settings")]
|
|
public float dashSpeed = 10f;
|
|
public float dashDuration = 0.5f;
|
|
|
|
|
|
public override void Execute(ServerCharacter character, Vector3 targetPosition, Vector3 targetRotation)
|
|
{
|
|
Debug.Log($"Executing DashNCrash for character {character.OwnerClientId} at {targetPosition}.");
|
|
|
|
// Start the dash
|
|
character.Movement.StartDash(targetPosition, dashSpeed, dashDuration);
|
|
|
|
// Delay spawning the slow zone until after the dash
|
|
character.StartCoroutine(SpawnSlowZoneAfterDash(character, targetPosition));
|
|
}
|
|
|
|
private IEnumerator SpawnSlowZoneAfterDash(ServerCharacter character, Vector3 position)
|
|
{
|
|
yield return new WaitForSeconds(dashDuration + 0.25f);
|
|
|
|
// Spawn the slow zone prefab at the dash's end position
|
|
var prefab = GetPrefab();
|
|
if (prefab != null)
|
|
{
|
|
GameObject instance = Instantiate(prefab, character.transform.position, Quaternion.identity);
|
|
var networkObject = instance.GetComponent<NetworkObject>();
|
|
|
|
if (networkObject != null)
|
|
{
|
|
networkObject.Spawn();
|
|
Debug.Log($"Slow Zone spawned at {position}.");
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError("Slow Zone prefab must have a NetworkObject component.");
|
|
}
|
|
}
|
|
}
|
|
}
|