IEnumerator Follow() { target = path.Dequeue(); float startTime = Time.time; while (true) { //move towards current target float lerpNumb = (Time.time - startTime) / speed; Vector2 newPos = Vector2.Lerp(myTrans.position, BoardMaker.IndexToPos(Data.instance.boardSize, target), lerpNumb); myTrans.position = new Vector3(newPos.x, newPos.y, myTrans.position.z); //check reset if (Vector3.Distance(myTrans.position, BoardMaker.IndexToPos(Data.instance.boardSize, target)) < 0.1f) { if (path.Count == 0) { break; } //increment target = path.Dequeue(); startTime = Time.time; } yield return(null); } movin = false; }
void SetupBases(Vector2Int pos) { baseZone.Add(pos); Unit_Node baseTemp = Instantiate(Data.instance.playerBaseObj, BoardMaker.IndexToPos(new Vector2Int(currBoard.GetLength(0), currBoard.GetLength(1)), pos), Quaternion.identity, baseHolder).GetComponent <Unit_Node>(); currBoard[pos.x, pos.y].unitObj = (Unit_Base)baseTemp; currBoard[pos.x, pos.y].unitObj.indexPos = pos; }
public void ShowPath(Vector2Int[] path) { ClearPath(); foreach (Vector2Int pos in path) { debugPath.Add(Instantiate(debugObj, BoardMaker.IndexToPos(new Vector2Int(currBoard.GetLength(0), currBoard.GetLength(1)), pos), Quaternion.identity, PathHolder)); } }
void SetupWall(Vector2Int pos) { Unit_Wall wallTemp = Instantiate(Data.instance.wallObj, BoardMaker.IndexToPos(new Vector2Int(currBoard.GetLength(0), currBoard.GetLength(1)), pos), Quaternion.Euler(0, 0, 45), blockerHolder).GetComponent <Unit_Wall>(); wallTemp.indexPos = pos; currBoard[pos.x, pos.y].unitObj = (Unit_Base)wallTemp; numberOfWalls++; UpdateText(); }
void SetupSpawners(Vector2Int pos) { Unit_Spawn spawnerTemp = Instantiate(Data.instance.spawnerObj, BoardMaker.IndexToPos(new Vector2Int(currBoard.GetLength(0), currBoard.GetLength(1)), pos), Quaternion.identity, SpawnerHolder).GetComponent <Unit_Spawn>(); currBoard[pos.x, pos.y].unitObj = (Unit_Base)spawnerTemp; currBoard[pos.x, pos.y].unitObj.indexPos = pos; spawnerTemp.StartUp(); spHandler.spawners.Add(spawnerTemp); }
public static Vector2 IndexToTurretPos(Vector2Int boardSize, Vector2Int position) { Vector2 toReturn = BoardMaker.IndexToPos(boardSize, position); return(new Vector2(toReturn.x + 0.5f, toReturn.y + 0.5f)); }