示例#1
0
    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);
    }
示例#2
0
 public void RemoveOldestPiece()
 {
     if (pieces.Count > 1)
     {
         LevelPieceBasic oldestPiece = pieces[0];
         pieces.RemoveAt(0);
         Destroy(oldestPiece.gameObject);
     }
 }
示例#3
0
 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);
 }
示例#4
0
    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);
    }