Skip to content

Commit 2af3f3f

Browse files
author
JasonNumberThirteen
committed
Fix displaying of the path trail dependant on the toggle UI
1 parent 313baff commit 2af3f3f

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

Assets/Project/Scripts/Game Objects/MapTilePathTrailIndicator.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ public void Setup(MapTileNode currentMapTileNode, MapTileNode nextMapTileNode)
2222
initialPosition = transform.position;
2323
}
2424

25+
public void SetActive(bool active)
26+
{
27+
gameObject.SetActive(active);
28+
}
29+
2530
private void Update()
2631
{
2732
if(Mathf.Approximately(movementPeriodOfOscillation, 0f))

Assets/Project/Scripts/Managers/PathTrailManager.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ public class PathTrailManager : MonoBehaviour
55
{
66
[SerializeField] private MapTilePathTrailIndicator mapTilePathTrailIndicatorPrefab;
77

8-
private bool pathTrailIsEnabled;
8+
private bool pathTrailIsEnabled;
99
private PathfindingManager pathfindingManager;
1010

1111
private readonly List<MapTilePathTrailIndicator> mapTilePathTrailIndicators = new();
1212

1313
public void SetPathTrailEnabled(bool enabled)
1414
{
1515
pathTrailIsEnabled = enabled;
16+
17+
mapTilePathTrailIndicators.ForEach(mapTilePathTrailIndicator => mapTilePathTrailIndicator.SetActive(pathTrailIsEnabled));
1618
}
1719

1820
private void Awake()
@@ -49,7 +51,7 @@ private void RegisterToListeners(bool register)
4951

5052
private void OnPathWasFound(List<MapTileNode> mapTileNodes)
5153
{
52-
if(!pathTrailIsEnabled || mapTilePathTrailIndicatorPrefab == null)
54+
if(mapTilePathTrailIndicatorPrefab == null)
5355
{
5456
return;
5557
}
@@ -60,6 +62,7 @@ private void OnPathWasFound(List<MapTileNode> mapTileNodes)
6062
var mapTilePathTrailIndicator = Instantiate(mapTilePathTrailIndicatorPrefab, currentMapTileNode.transform.position, Quaternion.identity);
6163

6264
mapTilePathTrailIndicator.Setup(currentMapTileNode, mapTileNodes[i - 1]);
65+
mapTilePathTrailIndicator.SetActive(pathTrailIsEnabled);
6366
mapTilePathTrailIndicators.Add(mapTilePathTrailIndicator);
6467
}
6568
}

0 commit comments

Comments
 (0)