Fixed some bugs

dev-main-mobile
Hazim Bin Ijaz 1 month ago
parent 06413cabc9
commit c89948611b

@ -11,6 +11,7 @@ using UnityEngine.AI;
public class AbilitySystem : NetworkBehaviour
{
private Camera mainCamera;
[Header("Assigned Abilities")]
public List<Ability> abilities = new List<Ability>();
public AbilityUI[] abilitiesUI;
@ -40,6 +41,9 @@ public class AbilitySystem : NetworkBehaviour
[Header("Executioner Settings")]
[SerializeField] private LineRenderer lineIndicator;
private bool _isPlacingExecutioner;
private Vector3 executionerStartPos;
private Vector3 executionerEndPos;
private void InitializeAbilityCursorMap()
{
@ -57,6 +61,7 @@ public class AbilitySystem : NetworkBehaviour
private void Awake()
{
m_Agent = GetComponent<NavMeshAgent>();
mainCamera = Camera.main;
}
private void Start()
@ -129,18 +134,19 @@ public class AbilitySystem : NetworkBehaviour
DeactivateIndicators();
}
}
private Vector3 executionerStartPos;
private Vector3 executionerEndPos;
private void HandleExecutionerPlacement()
{
lineIndicator.gameObject.SetActive(true);
if (Input.GetMouseButtonDown(0))
{
if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out var hit))
if (Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition), out var hit))
{
executionerStartPos = hit.point;
executionerEndPos = hit.point;
lineIndicator.positionCount = 2; // Ensure it has enough positions before setting them
lineIndicator.SetPosition(0, executionerStartPos);
lineIndicator.SetPosition(1, executionerEndPos);
}
@ -148,7 +154,7 @@ public class AbilitySystem : NetworkBehaviour
if (Input.GetMouseButton(0))
{
if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out var hit))
if (Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition), out var hit))
{
executionerEndPos = hit.point;
lineIndicator.SetPosition(1, executionerEndPos);
@ -158,10 +164,14 @@ public class AbilitySystem : NetworkBehaviour
if (Input.GetMouseButtonUp(0))
{
UseActiveAbility();
lineIndicator.positionCount = 0;
lineIndicator.positionCount = 2; // Reset to a valid number to prevent out-of-bounds errors
lineIndicator.SetPosition(0, Vector3.zero); // Reset positions to avoid old values
lineIndicator.SetPosition(1, Vector3.zero);
lineIndicator.gameObject.SetActive(false);
}
}
private void ManageVectorFenceIndicator()
{
@ -180,7 +190,7 @@ public class AbilitySystem : NetworkBehaviour
private void UpdateWallIndicatorPosition()
{
if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out RaycastHit hit))
if (Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition), out RaycastHit hit))
{
//wallIndicator.transform.position = hit.point; // Update position to follow the mouse
wallIndicator.transform.position = new Vector3(hit.point.x, 0, hit.point.z);
@ -190,7 +200,7 @@ public class AbilitySystem : NetworkBehaviour
private void StartWallPlacement()
{
if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out RaycastHit hit))
if (Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition), out RaycastHit hit))
{
wallSpawnPosition = new Vector3(hit.point.x, 0, hit.point.z); // Save spawn position
initialMousePosition = Input.mousePosition; // Store the initial mouse position on click
@ -212,7 +222,7 @@ public class AbilitySystem : NetworkBehaviour
// Check if the movement exceeds the threshold
if (mouseDistance >= mouseMoveThreshold)
{
Ray ray = Camera.main.ScreenPointToRay(currentMousePosition);
Ray ray = mainCamera.ScreenPointToRay(currentMousePosition);
if (Physics.Raycast(ray, out RaycastHit hit))
{
Vector3 direction = (new Vector3(hit.point.x, 0, hit.point.z) - wallIndicator.transform.position).normalized;
@ -408,7 +418,7 @@ public class AbilitySystem : NetworkBehaviour
private void UpdateIndicatorPosition()
{
if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out RaycastHit hit))
if (Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition), out RaycastHit hit))
{
currentAbilityIndicator.transform.position = new Vector3(hit.point.x, 0, hit.point.z);
currentAbilityIndicator.transform.localScale = Vector3.one * activeAbility.abilityRadius;

@ -238,18 +238,36 @@ public class CrowManager : NetworkBehaviour
[Rpc(SendTo.Everyone)]
private void NotifySwapForesightDecisionClientRpc(ulong senderId, Vector3 receiverPos, bool isAccepted)
{
if (currentCrow && currentCrow.clientCharacter)
if (currentCrow == null)
{
if (isAccepted)
{
FindObjectOfType<CrowsForesightPrefab>().OnSwapAccepted(senderId, receiverPos);
}
else
{
FindObjectOfType<CrowsForesightPrefab>().OnSwapRejected(senderId, receiverPos);
}
Debug.LogError("[CrowManager] Error: currentCrow is null!");
return;
}
if (currentCrow.clientCharacter == null)
{
Debug.LogError("[CrowManager] Error: currentCrow.clientCharacter is null!");
return;
}
var foresightPrefab = FindObjectOfType<CrowsForesightPrefab>();
if (foresightPrefab == null)
{
Debug.LogError("[CrowManager] Error: CrowsForesightPrefab not found!");
return;
}
if (isAccepted)
{
foresightPrefab.OnSwapAccepted(senderId, receiverPos);
}
else
{
foresightPrefab.OnSwapRejected(senderId, receiverPos);
}
}
[Rpc(SendTo.Everyone)]

Loading…
Cancel
Save