Working on slow down ability
parent
1afc48072e
commit
671567bb81
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: a56539f7f1d01564e96fc5270dbf94f7
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -0,0 +1,19 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!114 &11400000
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 0}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 4e7350d0607d7cc46a92f7ff596ad88d, type: 3}
|
||||||
|
m_Name: SlowZoneAbility
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
abilityName: Slowdown Area
|
||||||
|
abilityKey: Slowdown
|
||||||
|
keybind: 113
|
||||||
|
cooldownTime: 3
|
||||||
|
slowZonePrefab: {fileID: 5818330108676053786, guid: 4979352732bf84b44a9c789bef80b18a, type: 3}
|
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e4794e2f71f66a74486c797344695ce7
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 11400000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ce2326204c1815d48a8b749dcea9caf2
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -0,0 +1,122 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!1 &5818330108676053786
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 5066519206278508126}
|
||||||
|
- component: {fileID: 5158718991394562100}
|
||||||
|
- component: {fileID: 825873091886110301}
|
||||||
|
- component: {fileID: 8294231852451494523}
|
||||||
|
- component: {fileID: 7596904637393423818}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: SlowDownZonePrefab
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!4 &5066519206278508126
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 5818330108676053786}
|
||||||
|
serializedVersion: 2
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||||
|
m_LocalScale: {x: 0.5, y: 0.5, z: 0.5}
|
||||||
|
m_ConstrainProportionsScale: 1
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 0}
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!33 &5158718991394562100
|
||||||
|
MeshFilter:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 5818330108676053786}
|
||||||
|
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
|
||||||
|
--- !u!23 &825873091886110301
|
||||||
|
MeshRenderer:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 5818330108676053786}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_CastShadows: 1
|
||||||
|
m_ReceiveShadows: 1
|
||||||
|
m_DynamicOccludee: 1
|
||||||
|
m_StaticShadowCaster: 0
|
||||||
|
m_MotionVectors: 1
|
||||||
|
m_LightProbeUsage: 1
|
||||||
|
m_ReflectionProbeUsage: 1
|
||||||
|
m_RayTracingMode: 2
|
||||||
|
m_RayTraceProcedural: 0
|
||||||
|
m_RenderingLayerMask: 1
|
||||||
|
m_RendererPriority: 0
|
||||||
|
m_Materials:
|
||||||
|
- {fileID: 2100000, guid: 2758e3f8ea8e3644c85864c0cc87f779, type: 2}
|
||||||
|
m_StaticBatchInfo:
|
||||||
|
firstSubMesh: 0
|
||||||
|
subMeshCount: 0
|
||||||
|
m_StaticBatchRoot: {fileID: 0}
|
||||||
|
m_ProbeAnchor: {fileID: 0}
|
||||||
|
m_LightProbeVolumeOverride: {fileID: 0}
|
||||||
|
m_ScaleInLightmap: 1
|
||||||
|
m_ReceiveGI: 1
|
||||||
|
m_PreserveUVs: 0
|
||||||
|
m_IgnoreNormalsForChartDetection: 0
|
||||||
|
m_ImportantGI: 0
|
||||||
|
m_StitchLightmapSeams: 1
|
||||||
|
m_SelectedEditorRenderState: 3
|
||||||
|
m_MinimumChartSize: 4
|
||||||
|
m_AutoUVMaxDistance: 0.5
|
||||||
|
m_AutoUVMaxAngle: 89
|
||||||
|
m_LightmapParameters: {fileID: 0}
|
||||||
|
m_SortingLayerID: 0
|
||||||
|
m_SortingLayer: 0
|
||||||
|
m_SortingOrder: 0
|
||||||
|
m_AdditionalVertexStreams: {fileID: 0}
|
||||||
|
--- !u!114 &8294231852451494523
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 5818330108676053786}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: d5a57f767e5e46a458fc5d3c628d0cbb, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
GlobalObjectIdHash: 4101054131
|
||||||
|
InScenePlacedSourceGlobalObjectIdHash: 0
|
||||||
|
AlwaysReplicateAsRoot: 0
|
||||||
|
SynchronizeTransform: 1
|
||||||
|
ActiveSceneSynchronization: 0
|
||||||
|
SceneMigrationSynchronization: 1
|
||||||
|
SpawnWithObservers: 1
|
||||||
|
DontDestroyWithOwner: 0
|
||||||
|
AutoObjectParentSync: 1
|
||||||
|
--- !u!114 &7596904637393423818
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 5818330108676053786}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 16c014692584a9a438b902616cc2dd35, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
zoneRadius: 5
|
||||||
|
slowDuration: 3
|
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 4979352732bf84b44a9c789bef80b18a
|
||||||
|
PrefabImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -0,0 +1,39 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public abstract class Ability : ScriptableObject
|
||||||
|
{
|
||||||
|
[Header("Ability Settings")]
|
||||||
|
public string abilityName;
|
||||||
|
public string abilityKey;
|
||||||
|
public KeyCode keybind; // Key to activate the ability
|
||||||
|
public float cooldownTime; // Cooldown duration in seconds
|
||||||
|
|
||||||
|
private float lastActivationTime;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks if the ability can be activated (e.g., not on cooldown).
|
||||||
|
/// </summary>
|
||||||
|
public bool CanActivate()
|
||||||
|
{
|
||||||
|
return Time.time >= lastActivationTime + cooldownTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Invokes the ability.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="owner">The GameObject or player triggering this ability.</param>
|
||||||
|
public void TryActivate(GameObject owner)
|
||||||
|
{
|
||||||
|
if (CanActivate())
|
||||||
|
{
|
||||||
|
Activate(owner);
|
||||||
|
lastActivationTime = Time.time;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.Log($"{abilityName} is on cooldown.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void Activate(GameObject owner); // Logic for the specific ability
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 4d2f9f4fdfd486f409d0defeead4992f
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -0,0 +1,78 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using Unity.Netcode;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class AbilitySystem : MonoBehaviour
|
||||||
|
{
|
||||||
|
[Header("Assigned Abilities")]
|
||||||
|
public List<Ability> abilities = new List<Ability>();
|
||||||
|
|
||||||
|
private Ability activeAbility; // Tracks the currently active ability in "spawn mode"
|
||||||
|
private bool isAbilityActive = false;
|
||||||
|
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
// If ability mode is active, listen for mouse input to activate ability
|
||||||
|
if (isAbilityActive && Input.GetMouseButtonDown(0))
|
||||||
|
{
|
||||||
|
UseActiveAbility();
|
||||||
|
ToggleAbilityMode(activeAbility);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Activates ability by key (called externally).
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key">The key assigned to an ability.</param>
|
||||||
|
public void ActivateAbilityByKey(string key)
|
||||||
|
{
|
||||||
|
foreach (var ability in abilities)
|
||||||
|
{
|
||||||
|
if (ability.abilityKey == key)
|
||||||
|
{
|
||||||
|
ToggleAbilityMode(ability);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Debug.LogWarning($"No ability assigned to key {key}.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Toggles the ability activation mode.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ability">The ability to toggle.</param>
|
||||||
|
private void ToggleAbilityMode(Ability ability)
|
||||||
|
{
|
||||||
|
if (isAbilityActive && activeAbility == ability)
|
||||||
|
{
|
||||||
|
DeactivateAbilityMode();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ActivateAbilityMode(ability);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ActivateAbilityMode(Ability ability)
|
||||||
|
{
|
||||||
|
isAbilityActive = true;
|
||||||
|
activeAbility = ability;
|
||||||
|
Debug.Log($"Ability {ability.name} activated! Click to use.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DeactivateAbilityMode()
|
||||||
|
{
|
||||||
|
isAbilityActive = false;
|
||||||
|
activeAbility = null;
|
||||||
|
Debug.Log("Ability mode deactivated.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UseActiveAbility()
|
||||||
|
{
|
||||||
|
if (activeAbility != null)
|
||||||
|
{
|
||||||
|
activeAbility.TryActivate(gameObject);
|
||||||
|
DeactivateAbilityMode(); // Ability used, deactivate mode
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 9d1377d8a6afd7d4fbc33f3db37363bd
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -0,0 +1,35 @@
|
|||||||
|
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}.");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 4e7350d0607d7cc46a92f7ff596ad88d
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -0,0 +1,72 @@
|
|||||||
|
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.GetComponent<NavMeshAgent>().speed /= 2;
|
||||||
|
// player.Movement.SetMovementSpeed(originalSpeed * slowMultiplier);
|
||||||
|
|
||||||
|
// Wait for the slow duration
|
||||||
|
yield return new WaitForSeconds(slowDuration);
|
||||||
|
|
||||||
|
// Restore the original speed
|
||||||
|
player.GetComponent<NavMeshAgent>().speed /= 2;
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 16c014692584a9a438b902616cc2dd35
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
Loading…
Reference in New Issue