Пример #1
0
    /// <summary>
    /// Place the pill at its final resting place
    /// </summary>
    private void PlacePill()
    {
        //Test if the pill has stayed still for a long time
        if (stillTimer <= 0)
        {
            //Get the left and right half of the pill
            GameObject left  = transform.Find("Left").gameObject;
            GameObject right = transform.Find("Right").gameObject;

            //Set the position the halfs occupy on the grid
            field.GetComponent <FieldGrid>().gameObjects[gridPos1] = left;
            field.GetComponent <FieldGrid>().gameObjects[gridPos2] = right;

            //Check if there are any matches
            field.GetComponent <FieldGrid>().RemoveMatches(gridPos1);
            field.GetComponent <FieldGrid>().RemoveMatches(gridPos2);

            //Set the position of the individual pill pieces
            left.GetComponent <PillPiece>().gridPos  = gridPos1;
            right.GetComponent <PillPiece>().gridPos = gridPos2;

            //Destryo this script
            Destroy(this);
        }
    }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        //Test if the piece isn't apart of a pill
        TurnToPiece();

        //Determin if the piece is still apart of a pill
        if (transform.parent.childCount != 1 &&
            !transform.parent.GetComponent <Pill>() &&
            transform.parent.name.Contains("Pill"))
        {
            //Test if the pill can fall
            MovePill(new Vector2(0, 1));
        }

        //Allow the peice to fall by itself
        if (allowFall)
        {
            PieceFall();
            SetPosition();
            PlacePiece();
        }

        //Wait for everything to stop moving before testing matches
        if (field.movingPieces.Count == 0)
        {
            field.GetComponent <FieldGrid>().RemoveMatches(gridPos);
        }

        if (field.gameOver)
        {
            Destroy(gameObject);
        }
    }