Beispiel #1
0
    public void CubeOscillates()
    {
        List <Oscillator> oscillators = obstacleSpawner.GetComponentsInChildren <Oscillator>(true).ConvertToList().RemoveNullReferences();

        Obstacle o        = null;
        int      attempts = 0;
        bool     d        = false;

        while (o == null || !oscillators.Contains(o.GetComponent <Oscillator>()) && attempts < 5)
        {
            o = GetRandomObstacle(out d);
            attempts++;
        }
        if (o != null)
        {
            Oscillator c = o.GetOscillator();

            if (c != null)
            {
                if (1.PlusOrMinus() >= 0)
                {
                    c.IncreaseSpeed();
                }
                else
                {
                    c.IncreaseMagnitude();
                }
            }
            else
            {
                o.SetOscillator(o.gameObject.AddComponent <Oscillator>());
            }

            o.PlaySound();

            if (d)
            {
                o.gameObject.SetActive(false);
            }
        }
    }