void CalculatePlayerIndex() { float x = 0.0f; float y = 0.0f; if (GameManager.Instance.charChoice == true) { x = Player1.transform.position.x; y = Player1.transform.position.y; } else { x = Player2.transform.position.x; y = Player2.transform.position.y; } PlayerIndexJ = (int)x / (int)(5 * TileInterval); PlayerIndexI = (int)y / (int)(5 * TileInterval); if (PlayerIndexI >= RangeI) { PlayerIndexI = RangeI - 1; } if (PlayerIndexJ >= RangeJ) { PlayerIndexJ = RangeJ - 1; } if (CurrentMiniFieldIndexI != PlayerIndexI || CurrentMiniFieldIndexJ != PlayerIndexJ) { CurrentMiniFieldIndexI = PlayerIndexI; CurrentMiniFieldIndexJ = PlayerIndexJ; CurrentField = MiniFieldMap[CurrentMiniFieldIndexI, CurrentMiniFieldIndexJ]; } }
void Start() { RangeI = 5; RangeJ = 5; CurrentMiniFieldIndexI = RangeI - 1; MiniFieldMap = new MiniField[RangeI, RangeJ]; Data = new FieldData(Stage); PrevPos = new Vector2(); if (GenerateField == true) { for (int i = 0; i < RangeI; i++) { for (int j = 0; j < RangeJ; j++) { int[,] dataMap = Data.GetPartialMap(RangeI - i - 1, j); if (dataMap == null) { continue; } MiniFieldMap[i, j] = Instantiate(MField) as MiniField; MiniFieldMap[i, j].name = "minifield_" + i + "_" + j; MiniFieldMap[i, j].SetMainField(this); MiniFieldMap[i, j].SetStartPosition(new Vector2(j * 5 * TileInterval, i * 5 * TileInterval)); MiniFieldMap[i, j].SetInterval(TileInterval); MiniFieldMap[i, j].SetMap(dataMap); MiniFieldMap[i, j].Init(); MiniFieldMap[i, j].transform.SetParent(transform); } } } else { for (int i = 0; i < RangeI; i++) { for (int j = 0; j < RangeJ; j++) { int[,] dataMap = Data.GetPartialMap(RangeI - i - 1, j); if (dataMap == null) { continue; } MiniFieldMap[i, j] = GameObject.Find("minifield_" + i + "_" + j).GetComponent <MiniField>(); MiniFieldMap[i, j].SetMainField(this); MiniFieldMap[i, j].SetStartPosition(new Vector2(j * 5 * TileInterval, i * 5 * TileInterval)); MiniFieldMap[i, j].SetInterval(TileInterval); MiniFieldMap[i, j].SetMap(dataMap); MiniFieldMap[i, j].Init(); } } } CurrentField = MiniFieldMap[CurrentMiniFieldIndexI, CurrentMiniFieldIndexJ]; CalculatePlayerIndex(); }