Ejemplo n.º 1
0
    public void Update()
    {
        if (isActive)
        {
            if (state == CameraState.Preview)
            {
                x += Input.GetAxis("Mouse X") * 5f;
                y -= Input.GetAxis("Mouse Y") * 5f;
                y  = ClampAngle(y, 15, 80);

                Camera.main.GetComponent <Transform>().position = Quaternion.Euler(y, x, 0) * new Vector3(0, 0, -10) + (transform.position + cameraPos);
                Camera.main.GetComponent <Transform>().LookAt(transform.position + cameraPos);

                if (Input.GetMouseButtonDown(0))
                {
                    StartCoroutine(ExitPreview());
                }
            }
            else if (state == CameraState.Game)
            {
                if (Input.GetKey(KeyCode.LeftArrow))
                {
                    ballY -= 55 * Time.deltaTime;
                }
                if (Input.GetKey(KeyCode.RightArrow))
                {
                    ballY += 55 * Time.deltaTime;
                }

                if (Input.GetKey(KeyCode.UpArrow))
                {
                    ballPower += 75 * Time.deltaTime;
                }
                if (Input.GetKey(KeyCode.DownArrow))
                {
                    ballPower -= 75 * Time.deltaTime;
                }

                ballPower = Mathf.Clamp(ballPower, 0.0f, maxPower);

                Camera.main.GetComponent <Transform>().position = ball.transform.position + new Vector3(-3 * Mathf.Sin(ballY * Mathf.Deg2Rad), 2, -3 * Mathf.Cos(ballY * Mathf.Deg2Rad));
                Camera.main.GetComponent <Transform>().rotation = Quaternion.LookRotation(ball.transform.position - Camera.main.GetComponent <Transform>().position);

                if (Input.GetKeyDown(KeyCode.Space))
                {
                    if (ball.GetComponent <Rigidbody>().velocity.magnitude < 0.75f)
                    {
                        DoShoot(ball.transform.position - Camera.main.GetComponent <Transform>().position, ballPower);
                    }
                }
            }
            else if (state == CameraState.Post)
            {
                if (Input.GetMouseButtonDown(0))
                {
                    course.FinishHole();
                }
            }
        }
    }