public void GoTo(Vector2Int dest) { List <Vector2Int> path = PathFinding.AStar.FindPath(levelInfo.tiles, m_characterMovement.coordinate, dest); if (path == null) { return; } m_path = path; m_pathIndex = 0; // skip the first if already there if (m_path[m_pathIndex] == m_characterMovement.coordinate) { m_pathIndex++; } destination = dest; if (m_characterMovement.coordinate == destination) { m_characterMovement.GoTo(dest); OnArrive?.Invoke(destination); } else { m_characterMovement.GoTo(m_path[m_pathIndex]); } }
private void InitPlayer() { playerGO = Instantiate(playerPrefab, new Vector3(levelManager.info.playerStart.x, levelManager.info.playerStart.y), Quaternion.identity); GridCharacterMovement movementComp = playerGO.GetComponent <GridCharacterMovement>(); movementComp.coordinate = levelManager.info.playerStart; movementComp.levelManager = levelManager; movementComp.GoTo(movementComp.coordinate); //Camera.main.GetComponent<FollowGameObject>().target = playerGO; }
private void InitGhost() { for (int i = 0; i < 1; i++) { GameObject ghostGO = Instantiate(ghostPrefab, new Vector3(levelManager.info.ghostSpawn.x, levelManager.info.ghostSpawn.y), Quaternion.identity); GridCharacterMovement movementCompG = ghostGO.GetComponent <GridCharacterMovement>(); movementCompG.coordinate = levelManager.info.ghostSpawn; movementCompG.levelManager = levelManager; movementCompG.GoTo(levelManager.info.ghostSpawn); ghostGO.GetComponent <GhostAI>().player = playerGO; ghostGO.GetComponent <GhostAI>().levelinfo = levelManager.info; ghostGO.GetComponent <GridCharacterPathFinding>().levelInfo = levelManager.info; } }