Esempio n. 1
0
    void ReuseRemovedFood(FoodItems _food)
    {
        // After drop down the foods, there is hole at the top, fill it up with the food we removed and give it a new food type from prefab
        int foodType = Random.Range(0, foodPrefabs.Length);

        _food.rowIndex = (int)Def.rowCount;
        _food.CreateFood(foodType, foodPrefabs[foodType]);

        // Put it at the top frist
        _food.UpdatePosition(_food.rowIndex, _food.columIndex);

        // Drop it down slowly
        _food.rowIndex--;
        SetFoodItem(_food.rowIndex, _food.columIndex, _food);
        _food.UpdatePosition(_food.rowIndex, _food.columIndex, true);
    }
Esempio n. 2
0
    FoodItems AddRandomFoodItem(int _rowIndex, int _columIndex)
    {
        // Spawn a gameobject under the foodSpawner
        int        foodType = Random.Range(0, foodPrefabs.Length);
        GameObject item     = new GameObject("Item");

        item.transform.SetParent(foodSpawner, false);

        // Give the new spawned gameobject a boxcollider2d and the fooditems.cs we made
        item.AddComponent <BoxCollider2D>().size = Vector2.one * Def.cellSize;
        FoodItems fooditems = item.AddComponent <FoodItems>();

        // Give the new spawned a new position and image var its row and colum and prefab
        fooditems.UpdatePosition(_rowIndex, _columIndex);
        fooditems.CreateFood(foodType, foodPrefabs[foodType]);
        return(fooditems);
    }