How to Get 360 degree of angle while dragging object

I tried to find angle of my circle while i drag it around.
I can find this if my main Camera is not rotated, but in this case my main Camera is
rotated in X axis 90 degree

// This Script is working if the Camera doesn’t rotated

void Update () {
        if (Input.GetMouseButton(0))
        {
            Vector3 fingerPos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 5f));
            transform.position = new Vector3(fingerPos.x, fingerPos.y, transform.position.z);
            float angle = Mathf.Atan2(transform.position.y, transform.position.x) * Mathf.Rad2Deg;
            if (angle < 0)
                angle += 360;
            
        }
	}

How do it find angle of the sphere if my Camera.main.transform.Rotate(90,0,0); ?

8928-circle1.png

The Z value you are using in your ScreenToWorldPoint() does not match your ‘Y’ value unless your object happened to be at ‘5’. I modded you code a bit. Try this:

void Update () {
        if (Input.GetMouseButton(0))
        {
            Vector3 fingerPos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Mathf.Abs(transform.position.y - Camera.main.transform.position.y)));
            transform.position = fingerPos;
            float angle = Mathf.Atan2(transform.position.z, transform.position.x) * Mathf.Rad2Deg;
            if (angle < 0.0f)
                angle += 360.0f;
			
			Debug.Log ("angle="+angle);
 
        }
    }

Note the angle you are calculating is between your object and the world origin. If you moved the camera (i.e. it was no longer pointing at the origin), then you code would appear to not work.

This will do the same too.
Transform.InverseTransformPoint: Transforms the position x, y, z from world space to local space. And try to use transTemp to detect your first position before you drag, rotate, and find angle between your firt position and next position.

public Transform transTemp; // Drag gameobject empty in the inspector
	
	// Update is called once per frame
	void Update () {
        if (Input.GetMouseButtonDown(0))
            transTemp.position = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 5f));

        if (Input.GetMouseButton(0))
        {
            Vector3 fingerPos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 5f));
            transform.position = new Vector3(fingerPos.x, transform.position.y, fingerPos.z);
            Vector3 relative = transTemp.InverseTransformPoint(fingerPos);
            float angle = Mathf.Atan2(relative.x, relative.z) * Mathf.Rad2Deg;
            if (angle < 0)
                angle += 360;
            Debug.Log(angle);
        }
	}