예제 #1
0
    private void FixedUpdate()
    {
        // Movement
        if (moveInput != Vector2.zero)
        {
            tankController.Move(moveInput.x, moveInput.y);
        }

        // Aim
        if (mousePosition != Vector2.zero)
        {
            if (currentControlScheme == "Keyboard&Mouse")
            {
                Ray ray = cam.ScreenPointToRay(mousePosition);
                if (debugMode)
                {
                    Debug.DrawRay(ray.origin, ray.direction * 50, Color.yellow);
                }

                RaycastHit hit;
                if (Physics.Raycast(ray, out hit, 50))
                {
                    tankController.AimAtPoint(hit.point.x, hit.point.z);
                }
            }
            else if (currentControlScheme == "Gamepad")
            {
                if (mousePosition != Vector2.zero)
                {
                    if (debugMode)
                    {
                        Debug.DrawRay(transform.position, new Vector3(mousePosition.x, 0, mousePosition.y) * 50, Color.yellow);
                    }
                    tankController.AimAtDirection(mousePosition.x, mousePosition.y);
                }
            }
            else
            {
                Debug.LogWarning("Unknown control scheme, unable to handle.");
            }
        }

        if (fireInput == true)
        {
            tankController.Shoot();
        }
    }