public void Update() { if (_camera == null) { _camera = Camera.current; if (_camera == null) { return; } } if (_target == null) { var gameObjects = GameObject.FindGameObjectsWithTag("Target"); if (gameObjects.Length > 0) { _target = gameObjects[0]; } ; } _mousePositionInScreenCoordinates = IsometricMath.GetMousePositionInScreenCoordinates(); _mousePositionInWorldCoordinates = IsometricMath.GetMousePositionInWorldCoordinates(_camera); _cellCoordinates = IsometricMath.GetMousePositionOnMap(_camera); _centerOfCellPosition = IsometricMath.MapToWorld(_cellCoordinates.x, _cellCoordinates.y, IsometricMath.DrawType.FLOOR); if (Input.GetButton("Fire1")) { MoveTargetToMouse(); } }
public void SpawnTarget() { var point = FindWalkable(); var isoPosition = IsometricMath.MapToWorld(point.x, point.y, IsometricMath.DrawType.FLOOR); Target = Instantiate(TargetPrefab, isoPosition, Quaternion.identity); SetCartesianPosition(Target, point.x, point.y); }
public void SpawnSeekers() { for (var i = 0; i < NumberOfSeekers; i++) { var point = FindWalkable(); var isoPosition = IsometricMath.MapToWorld(point.x, point.y, IsometricMath.DrawType.FLOOR); var go = Instantiate(SeekerPrefab, isoPosition, Quaternion.identity); SetCartesianPosition(go, point.x, point.y); var seekAI = go.GetComponent <SeekAI>(); seekAI.Seek(Target.transform); } }
private void BuildMap() { var pathFinder = PathFinder.Instance; pathFinder.Init(GridSizeX, GridSizeY, Diagonals, 4); for (int x = 0; x < GridSizeX; x++) { for (int y = 0; y < GridSizeY; y++) { Vector3 drawLocation = IsometricMath.MapToWorld(x, y, IsometricMath.DrawType.TILE); var random = Random.Range(0, 10); if (random == 5) { var go = GameObject.Instantiate(CollidableTile, drawLocation, Quaternion.identity); SetCartesianPosition(go, x, y); pathFinder.Grid.SetWalkable(x, y, false); AddToMapFolder(go); } else if (random == 4) { var go = GameObject.Instantiate(TallCollidable, drawLocation, Quaternion.identity); SetCartesianPosition(go, x, y); pathFinder.Grid.SetWalkable(x, y, false); AddToMapFolder(go); } else if ((x % 2 == 0 && y % 2 == 0) || x % 2 == 1 && y % 2 == 1) { var go = GameObject.Instantiate(DarkTile, drawLocation, Quaternion.identity); SetCartesianPosition(go, x, y); AddToMapFolder(go); } else { var go = GameObject.Instantiate(LightTile, drawLocation, Quaternion.identity); SetCartesianPosition(go, x, y); AddToMapFolder(go); } } } }
private void UpdateDrawPosition(int newX, int newY) { transform.position = IsometricMath.MapToWorld(newX, newY, DrawPosition); }