public void UpdatePath() { SnapGrid snapGrid = SnapGrid.Instance; Vector2Int startCoord = snapGrid.GetCoordFromCentre(transform.position); Vector2Int endCoord = snapGrid.GetCoordFromCentre(_endTarget); CurrentPath = new LinkedList <Vector2>(); List <Vector2Int> coordList = _pathMgr.FindPath(startCoord, endCoord, _enemyAttack.DPS, _movement.MovementSpeed); if (coordList != null && coordList.Count > 0) { for (int i = 0; i < coordList.Count; ++i) { Vector2 newWaypoint = snapGrid.GetCellCentre(coordList[i]); CurrentPath.AddLast(newWaypoint); } } OnWaypointReached(transform.position); }
private void Update() { if (!IsPlacing) { if (Input.GetButtonUp("TogglePlacing")) { StartPlacing(ObjectPrefab); } return; } // Update preview Vector2 position = HelperFuncs.GetMousePositionWorld(); Vector2Int gridCoord = Grid.GetCoordFromCentre(position); position = Grid.GetCellCorner(gridCoord); bool isOccupied = GridObjMgr.IsOccupied(gridCoord, ObjectPrefab.OccupiedTiles); ObjectPreview.gameObject.SetActive(!isOccupied); ObjectPreview.transform.position = position; if (Input.GetButton("Place")) { if (!isOccupied) { Building building = Instantiate(ObjectPrefab, position, Quaternion.identity, GridObjMgr.transform); GridObjMgr.AddObject(building, gridCoord); } } if (Input.GetButtonUp("Cancel") || Input.GetButtonUp("TogglePlacing")) { StopPlacing(); } }