示例#1
0
        private void SpawnFood()
        {
            if (FoodManager.Instance.refreshFoodResource)
            {
                //_foodForSpawn = RandomFoodResource(FoodManager.Instance.FoodInfoSpaws);
                _foodForSpawn = FoodManager.Instance.FoodInfoSpaws;
                FoodManager.Instance.refreshFoodResource = false;
            }

            if (_indexFoodSpawn < _foodForSpawn.Count)
            {
                FoodInfoSpaw food = _foodForSpawn[_indexFoodSpawn];

                GameObject foodResource = Instantiate(_foodPrefab, transform.position, Quaternion.identity) as GameObject;
                foodResource.name = food.ID;
                foodResource.GetComponent <FoodInfoSpaw>().SetFoodSpawn(food.ID, food.Image, RandomSymbol());
                foodResource.GetComponent <SpriteRenderer>().sprite = food.Image;
                foodResource.GetComponent <FoodInfoSpaw>().InitSymbol();
                ++_indexFoodSpawn;
            }
            else
            {
                _indexFoodSpawn = 0;
            }
        }
示例#2
0
        private List <FoodInfoSpaw> RandomFoodResource(List <FoodInfoSpaw> foods)
        {
            List <FoodInfoSpaw> foodsRandom = new List <FoodInfoSpaw>();

            foodsRandom = foods;
            for (int i = 0; i < foodsRandom.Count; i++)
            {
                FoodInfoSpaw tmp = foodsRandom[i];
                int          r   = Random.Range(i, foodsRandom.Count);
                foodsRandom[i] = foodsRandom[r];
                foodsRandom[r] = tmp;
            }

            return(foodsRandom);
        }
示例#3
0
        private IEnumerator SpawnFoodResource()
        {
            if (FoodManager.Instance.refreshFoodResource)
            {
                //_foodForSpawn = RandomFoodResource(FoodManager.Instance.FoodInfoSpaws);
                _foodForSpawn = FoodManager.Instance.FoodInfoSpaws;
                FoodManager.Instance.refreshFoodResource = false;
            }

            if (_indexFoodSpawn < _foodForSpawn.Count)
            {
                FoodInfoSpaw food = _foodForSpawn[_indexFoodSpawn];

                GameObject foodResource = Instantiate(_foodPrefab, transform.position, Quaternion.identity) as GameObject;
                foodResource.transform.localScale = new Vector3(0.4f, 0.4f);
                foodResource.name = food.ID;
                if (_symbolForPowerUp.Count > 0)
                {
                    foodResource.GetComponent <FoodInfoSpaw>().SetFoodSpawn(food.ID, food.Image, _symbolForPowerUp);
                }
                else
                {
                    foodResource.GetComponent <FoodInfoSpaw>().SetFoodSpawn(food.ID, food.Image, RandomSymbol());
                }
                foodResource.GetComponent <SpriteRenderer>().sprite = food.Image;
                foodResource.GetComponent <FoodInfoSpaw>().InitSymbol();
                ++_indexFoodSpawn;
            }
            else
            {
                _indexFoodSpawn = 0;
            }
            yield return(new WaitForSeconds(_timeSpawn));

            _delaySpawnFood = false;
        }