Example #1
0
    // Update is called once per frame
    void Update()
    {
        Vector3 minForce = Vector3.up * (force * rotateMultiplier);
        Vector3 maxForce = Vector3.up * force;

        if (Input.GetKey(Managers.Control.KeyCodes["PushUp"]))
        {
            leftForce  = maxForce;
            rightForce = maxForce;
            direction  = 1;
            if (!engineAudio.isPlaying)
            {
                engineAudio.Play();
            }
        }
        else if (Input.GetKey(Managers.Control.KeyCodes["PushDown"]))
        {
            leftForce  = -maxForce;
            rightForce = -maxForce;
            direction  = -1;
            if (!engineAudio.isPlaying)
            {
                engineAudio.Play();
            }
        }
        else
        {
            leftForce  = Vector3.zero;
            rightForce = Vector3.zero;
        }

        //Разделил управление по осям для удобства игрока.
        if (Input.GetKey(Managers.Control.KeyCodes["PushLeft"]))
        {
            leftForce  = maxForce * direction;
            rightForce = minForce * direction;
            if (!engineAudio.isPlaying)
            {
                engineAudio.Play();
            }
        }
        else if (Input.GetKey(Managers.Control.KeyCodes["PushRight"]))
        {
            leftForce  = minForce * direction;
            rightForce = maxForce * direction;
            if (!engineAudio.isPlaying)
            {
                engineAudio.Play();
            }
        }

        if (leftForce == Vector3.zero && rightForce == Vector3.zero)
        {
            engineAudio.Stop();
        }

        uiGame.SetValueAltimeter(transform.position.y);
    }