コード例 #1
0
    //Spawn a random piece of food
    void ActivateFood()
    {
        if (foodEaten < maxFood)
        {
            int objIndex = Random.Range(0, foodLeftToSpawn.Count);

            //Spawn food in by making it active.
            foodLeftToSpawn[objIndex].SetActive(true);

            //Make arrow point to the new piece of food
            if (levelSpawner.GetLevel() > 0 && levelSpawner.GetLevelObject().name != "EasyLevel3(Clone)")
            {
                pointer.cubeRef = foodLeftToSpawn[objIndex];
            }

            //Set it to the gate parent
            foodLeftToSpawn[objIndex].transform.parent = transform.parent;

            //Remove from list now
            foodLeftToSpawn.RemoveAt(objIndex);

            foodEaten++;
        }
        else
        {
            Destroy(gameObject);  //Destroy self when max food amount is collected
        }
    }