Example #1
0
    private void DuplicateCandy(GameObject go)
    {
        BonusType         goBonus  = go.GetComponent <Shape>().Bonus;
        string            goType   = go.GetComponent <Shape>().Type;
        List <GameObject> newCandy = new List <GameObject>();

        // if the candy is horizontal or vertical, add both to the list
        if ((goBonus == BonusType.Horizontal) || (goBonus == BonusType.Vertical))
        {
            newCandy.Add(GetPrefabFromTypeAndBonus(goType, BonusType.Horizontal));
            newCandy.Add(GetPrefabFromTypeAndBonus(goType, BonusType.Vertical));
        }
        else
        {
            newCandy.Add(GetPrefabFromTypeAndBonus(goType, goBonus));
        }

        foreach (var item in shapes.GetAllShapes().MatchedCandy)
        {
            if (item.GetComponent <Shape>().Type == goType)
            {
                // only replace item if the BonusType is None to not downgrade the object
                if (item.GetComponent <Shape>().Bonus == BonusType.None)
                {
                    ReplaceCandy(item, newCandy[Random.Range(0, newCandy.Count)]);
                }
            }
        }
    }