|
|
|
@ -5,6 +5,8 @@ using Unity.BossRoom.Gameplay.GameplayObjects;
|
|
|
|
|
using Unity.BossRoom.Gameplay.GameplayObjects.Character;
|
|
|
|
|
using Unity.Netcode;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.AI;
|
|
|
|
|
using static Codice.Client.Common.WebApi.WebApiEndpoints;
|
|
|
|
|
|
|
|
|
|
public class AbilitySystem : NetworkBehaviour
|
|
|
|
|
{
|
|
|
|
@ -29,7 +31,11 @@ public class AbilitySystem : NetworkBehaviour
|
|
|
|
|
private Vector3 wallSpawnPosition;
|
|
|
|
|
private bool isWallPlacementStarted = false;
|
|
|
|
|
private bool isValidPlacement = true;
|
|
|
|
|
|
|
|
|
|
NavMeshAgent m_Agent;
|
|
|
|
|
private void Awake()
|
|
|
|
|
{
|
|
|
|
|
m_Agent = GetComponent<NavMeshAgent>();
|
|
|
|
|
}
|
|
|
|
|
void Update()
|
|
|
|
|
{
|
|
|
|
|
HandleAbilityMode();
|
|
|
|
@ -48,7 +54,7 @@ public class AbilitySystem : NetworkBehaviour
|
|
|
|
|
UpdateWallIndicatorPosition(); // Follow the mouse when ability is activated
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Input.GetMouseButtonDown(0) && isValidPlacement)
|
|
|
|
|
if (Input.GetMouseButtonDown(0))//AliSharoz && isValidPlacement)
|
|
|
|
|
{
|
|
|
|
|
StartWallPlacement();
|
|
|
|
|
}
|
|
|
|
@ -67,6 +73,9 @@ public class AbilitySystem : NetworkBehaviour
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
UseActiveAbility(); // Place the wall when LMB is released
|
|
|
|
|
isWallPlacementStarted = false;
|
|
|
|
|
Invoke(nameof(RepositionAgent), 0.5f);
|
|
|
|
|
Debug.Log("Invalid placement! Cannot place wall on top of another player.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -108,13 +117,15 @@ public class AbilitySystem : NetworkBehaviour
|
|
|
|
|
{
|
|
|
|
|
wallIndicator.transform.position = hit.point; // Update position to follow the mouse
|
|
|
|
|
|
|
|
|
|
//isValidPlacement = true;
|
|
|
|
|
//AliSharoz
|
|
|
|
|
isValidPlacement = IsPlacementValid(hit.point, wallIndicator.transform.rotation, playerLayer);
|
|
|
|
|
|
|
|
|
|
var meshRenderer = wallIndicator.GetComponent<MeshRenderer>();
|
|
|
|
|
if (meshRenderer != null)
|
|
|
|
|
{
|
|
|
|
|
meshRenderer.material = isValidPlacement ? validPlacementMaterial : invalidPlacementMaterial;
|
|
|
|
|
}
|
|
|
|
|
//var meshRenderer = wallIndicator.GetComponent<MeshRenderer>();
|
|
|
|
|
//if (meshRenderer != null)
|
|
|
|
|
//{
|
|
|
|
|
// meshRenderer.material = isValidPlacement ? validPlacementMaterial : invalidPlacementMaterial;
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -131,11 +142,45 @@ public class AbilitySystem : NetworkBehaviour
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
wallSpawnPosition = hit.point; // Save spawn position
|
|
|
|
|
initialMousePosition = Input.mousePosition; // Store the initial mouse position on click
|
|
|
|
|
isWallPlacementStarted = true;
|
|
|
|
|
Debug.Log("Cannot place the wall on top of another player.");
|
|
|
|
|
Invoke(nameof(RepositionAgent), 0.5f);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public float searchRadius = 5f;
|
|
|
|
|
|
|
|
|
|
private void RepositionAgent()
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("RepositionAgent()1");
|
|
|
|
|
//if (NavMesh.SamplePosition(currentPosition, out hit, 0.01f, NavMesh.AllAreas))
|
|
|
|
|
//if (m_Agent.isOnNavMesh == false)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("RepositionAgent()2");
|
|
|
|
|
Vector3 currentPosition = m_Agent.transform.position;
|
|
|
|
|
NavMeshHit hit;
|
|
|
|
|
|
|
|
|
|
// Sample the nearest point on the NavMesh
|
|
|
|
|
if (NavMesh.SamplePosition(currentPosition, out hit, searchRadius, NavMesh.AllAreas))
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("RepositionAgent()3");
|
|
|
|
|
Debug.Log($"Found nearest NavMesh point at {hit.position}");
|
|
|
|
|
m_Agent.Warp(hit.position); // Warp the agent to the nearest point without path recalculation
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("RepositionAgent()4");
|
|
|
|
|
Debug.LogError("No walkable NavMesh point found within the search radius!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//else
|
|
|
|
|
//{
|
|
|
|
|
// Debug.LogWarning("No valid NavMesh point found near the agent!");
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
private void RotateWallIndicator()
|
|
|
|
|
{
|
|
|
|
|
if (isWallPlacementStarted && wallIndicator != null)
|
|
|
|
@ -162,15 +207,18 @@ public class AbilitySystem : NetworkBehaviour
|
|
|
|
|
isValidPlacement = IsPlacementValid(wallIndicator.transform.position, wallIndicator.transform.rotation, playerLayer);
|
|
|
|
|
|
|
|
|
|
// Change indicator color based on placement validity
|
|
|
|
|
var meshRenderer = wallIndicator.GetComponent<MeshRenderer>();
|
|
|
|
|
if (meshRenderer != null)
|
|
|
|
|
{
|
|
|
|
|
meshRenderer.material = isValidPlacement ? validPlacementMaterial : invalidPlacementMaterial;
|
|
|
|
|
}
|
|
|
|
|
//AliSharoz
|
|
|
|
|
//var meshRenderer = wallIndicator.GetComponent<MeshRenderer>();
|
|
|
|
|
//if (meshRenderer != null)
|
|
|
|
|
//{
|
|
|
|
|
// meshRenderer.material = isValidPlacement ? validPlacementMaterial : invalidPlacementMaterial;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
if (!isValidPlacement)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("Cannot rotate wall here: Overlapping with another object.");
|
|
|
|
|
Invoke(nameof(RepositionAgent), 0.5f);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|