예제 #1
0
    // Update is called once per frame
    void Update()
    {
        if (loading)
        {
            transitionScript.Intro();
            loading = false;
        }
        else if (transitionScript.isCameraDefault())
        {
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
        }
        // Check if Game is being reset
        if (Input.GetKeyDown(KeyCode.R))
        {
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
        }
        // Check if Game is being reset
        if (Input.GetKeyDown(KeyCode.T))
        {
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
        }

        // Tilt Controls
        float zDir = 0f;
        float xDir = 0f;

        // If the Ball is in a transition scene disable controls
        if (!transitionScript.isTransitioning)
        {
            // Get Inputs
            if (Input.GetKey("left"))
            {
                zDir = 1f;
            }
            else if (Input.GetKey("right"))
            {
                zDir = -1f;
            }

            if (Input.GetKey("up"))
            {
                xDir = 1f;
            }
            else if (Input.GetKey("down"))
            {
                xDir = -1f;
            }
        }

        // If no Z input from player Rotate back to 0 quickly
        // Otherwise Lerp towards input destination
        if (zDir != 0)
        {
            transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(transform.rotation.eulerAngles.x, 0f, maxRotation * zDir), Time.deltaTime * rotationSpeed);
        }
        else
        {
            transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.Euler(transform.rotation.eulerAngles.x, 0f, 0f), Time.deltaTime * returnRotationSpeed);
        }

        // If no X input from player Rotate back to 0 quickly
        // Otherwise Lerp towards input destination
        if (xDir != 0)
        {
            transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(maxRotation * xDir, 0f, transform.rotation.eulerAngles.z), Time.deltaTime * rotationSpeed);
        }
        else
        {
            transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.Euler(0f, 0f, transform.rotation.eulerAngles.z), Time.deltaTime * returnRotationSpeed);
        }
    }