public void AddPiece() { float random = Random.Range(0.0f, 1.0f); int randomIndex = levelPrefabsWithProbability.Count - 1; for (int i = 0; i < levelPrefabsWithProbability.Count - 1; i++) { if (random < levelPrefabsWithProbability[i].probability) { if (lastprefab != i) { randomIndex = i; break; } else { continue; } } } LevelPieceBasic piece = (LevelPieceBasic)Instantiate(levelPrefabsWithProbability[randomIndex].levelpiece); lastprefab = randomIndex; ShowPiece(piece); }
public void RemoveOldestPiece() { if (pieces.Count > 1) { LevelPieceBasic oldestPiece = pieces[0]; pieces.RemoveAt(0); Destroy(oldestPiece.gameObject); } }
public void ShowPiece(LevelPieceBasic piece) { piece.transform.SetParent(this.transform, false); if (pieces.Count < 1) { piece.transform.position = new Vector2(levelStartPoint.position.x - piece.startPoint.localPosition.x, levelStartPoint.position.y - piece.exitPoint.localPosition.y); } else { piece.transform.position = new Vector2(pieces[pieces.Count - 1].exitPoint.position.x - pieces[pieces.Count - 1].startPoint.localPosition.x, pieces[pieces.Count - 1].exitPoint.position.y - pieces[pieces.Count - 1].exitPoint.localPosition.y); } pieces.Add(piece); }
public void AddPiece() { int randomIndex = Random.Range(0, levelPrefabs.Count - 1); LevelPieceBasic piece = (LevelPieceBasic)Instantiate(levelPrefabs[randomIndex]); piece.transform.SetParent(this.transform, false); if (pieces.Count < 1) { piece.transform.position = new Vector2( levelStartPoint.position.x - piece.startPoint.localPosition.x, levelStartPoint.position.y - piece.startPoint.localPosition.y); } else { piece.transform.position = new Vector2( pieces[pieces.Count - 1].exitPoint.position.x - pieces[pieces.Count - 1]. startPoint.localPosition.x, pieces[pieces.Count - 1].exitPoint.position.y - pieces[pieces.Count - 1]. startPoint.localPosition.y); } pieces.Add(piece); }