public IEnumerator CreateFoodLoop()
    {
        while (true)
        {
            //GetComponent<AudioSource>().Play();

            GameObject newFood = Instantiate(foodGameObject, transform.position + Vector3.up * 0.1f, Quaternion.identity);
            newFood.transform.rotation = Quaternion.Euler(-90, 0, 0);
            newFood.SetActive(true);
            newFood.GetComponent <Rigidbody>().useGravity = false;
            FlyingFood    flyingFood = newFood.GetComponent <FlyingFood>();
            FoodColorEnum color      = CalculateTableColor();
            flyingFood.SetTableColor(color);
            if (color == FoodColorEnum.red)
            {
                redSource.Play();
            }
            else if (color == FoodColorEnum.green)
            {
                greenSource.Play();
            }
            yield return(new WaitForSeconds(2));

            newFood.GetComponent <Rigidbody>().useGravity = true;
            flyingFood.ApplyForce(CalculateForceVectorWithRotation());
            yield return(new WaitForSeconds(5));
        }
    }
Example #2
0
    public void SetTableColor(FoodColorEnum tableColor)
    {
        switch (tableColor)
        {
        case FoodColorEnum.red:
            gameObject.tag = "PlateRedTag";
            GetComponent <MeshRenderer>().material = RedMaterial;
            break;

        case FoodColorEnum.green:
            gameObject.tag = "PlateGreenTag";
            GetComponent <MeshRenderer>().material = GreenMaterial;
            break;

        case FoodColorEnum.blue:
            gameObject.tag = "PlateBlueTag";
            GetComponent <MeshRenderer>().material = BlueMaterial;
            break;
        }
    }