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.
36 lines
979 B
C#
36 lines
979 B
C#
1 month ago
|
using UnityEngine;
|
||
|
using Unity.Netcode;
|
||
|
|
||
|
[CreateAssetMenu(menuName = "Abilities/Slow Zone Ability")]
|
||
|
public class SlowZoneAbility : Ability
|
||
|
{
|
||
|
[Header("Slow Zone Settings")]
|
||
|
public GameObject slowZonePrefab;
|
||
|
|
||
|
protected override void Activate(GameObject owner)
|
||
|
{
|
||
|
Camera mainCamera = Camera.main;
|
||
|
Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);
|
||
|
|
||
|
if (Physics.Raycast(ray, out RaycastHit hit))
|
||
|
{
|
||
|
Vector3 spawnPosition = hit.point;
|
||
|
|
||
|
if (owner.TryGetComponent(out NetworkObject networkOwner))
|
||
|
{
|
||
|
SpawnSlowZoneServerRpc(spawnPosition);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
[Rpc(SendTo.Server)]
|
||
|
private void SpawnSlowZoneServerRpc(Vector3 position)
|
||
|
{
|
||
|
GameObject slowZone = Instantiate(slowZonePrefab, position, Quaternion.identity);
|
||
|
slowZone.GetComponent<NetworkObject>().Spawn();
|
||
|
Debug.Log($"Slow Zone spawned at {position}.");
|
||
|
}
|
||
|
}
|