예제 #1
0
    public void SpawnFood()
    {
        if (food != null && food.foods != null)
        {
            int   randomIndex = UnityEngine.Random.Range(0, food.foods.Count);
            float x           = UnityEngine.Random.Range(-bounds.xMax, bounds.xMax);
            float z           = UnityEngine.Random.Range(-bounds.yMax, bounds.yMax);

            GameObject foodObjcet = Instantiate(foodPrefab);
            foodObjcet.transform.position = new Vector3(x, 0.5f, z);
            FoodProperties properties = foodObjcet.GetComponent <FoodProperties>();
            properties.SetFoodType(food.foods[randomIndex]);
        }
    }
예제 #2
0
    public void SpawnFood()
    {
        if (foodCollection != null && foodCollection.foods != null)
        {
            int randomIndex = UnityEngine.Random.Range(0, foodCollection.foods.Count);

            GameObject f = Instantiate(food);

            //Placing food in the grid
            Vector2 randomXY = GetRandomXY();

            f.transform.position = new Vector3(randomXY.x, 0, randomXY.y);

            FoodProperties properties = f.GetComponent <FoodProperties>();
            properties.SetFoodType(foodCollection.foods[randomIndex]);
        }
    }