Exemplo n.º 1
0
    /// <summary>
    /// During Update, we want to show the speed value of the platforms spinning.
    /// since both of the platforms that speed alter have the same speed, we only need to display the info of one.
    /// </summary>
    /// <returns>void</returns>
    void Update()
    {
        // assign the component
        ConstantSpinning cs = platform.GetComponentInChildren <ConstantSpinning>();

        // display the speed vaule.
        gameObject.GetComponent <TextMesh>().text = "Speed: " + cs.speed.ToString();
    }
Exemplo n.º 2
0
    /// <summary>
    /// When the player hits one of the buttons, depending on the value assigned ("the enum") it will add or subtract the speed from the platforms.
    /// </summary>
    /// <param name="other"> the other collider. which will in this case be the player.</param>
    /// <returns></returns>
    private void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Player")
        {
            switch (selector)
            {
            case IncreaseDecrease.ADD:
                foreach (GameObject platform in platforms)
                {
                    ConstantSpinning cs = platform.GetComponentInChildren <ConstantSpinning>();
                    if (cs != null)
                    {
                        cs.speed += 10;
                    }
                }
                break;

            case IncreaseDecrease.SUBTRACT:
                foreach (GameObject platform in platforms)
                {
                    ConstantSpinning cs = platform.GetComponentInChildren <ConstantSpinning>();
                    if (cs != null)
                    {
                        if (cs.speed > 9)
                        {
                            cs.speed -= 10;
                        }
                    }
                }
                break;

            default:
                break;
            }
        }
    }