using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Rotation : MonoBehaviour
{
    public Transform ball;
    float rotationY = 0f;
    float rotationX = 0f;
    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        float horizontalInput = 0;
        float verticalInput = 0;
#if UNITY_EDITOR
        horizontalInput = Input.GetAxis("Horizontal");
        verticalInput = Input.GetAxis("Vertical");
#else
        if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved)
        {
            horizontalInput = Input.GetTouch(0).deltaPosition.x;
            verticalInput = Input.GetTouch(0).deltaPosition.y;
        }
#endif
        if (horizontalInput != 0)
        {
            rotationY += horizontalInput;
            if (rotationY < -360)
            {
                rotationY += 360;
            }
            if (rotationY > 360)
            {
                rotationY -= 360;
            }
        }

        if (verticalInput != 0)
        {
            rotationX += verticalInput;
            if (rotationX < -360)
            {
                rotationX += 360;
            }
            if (rotationX > 360)
            {
                rotationX -= 360;
            }
        }

        ball.rotation = Quaternion.Euler(rotationX, rotationY, 0);
    }
}
