Search Unity

Trying rotate and drag 2D Object with mouse

Discussion in '2D' started by afifnuril, Jul 28, 2020.

  1. afifnuril

    afifnuril

    Joined:
    Jun 18, 2019
    Posts:
    1
    I have made the 2d object function move, but when I add the rotation function, if the object is moved then the object will move and rotate.
    Can anyone provide a solution for that?

    this the function (this used button to drag and rotate,I want to use the mouse)

    public void OnDrag(PointerEventData eventData)
    {
    //Debug.Log("OnDrag");

    string a = Itext.text.ToString();
    print(a);

    if (a == "Rotasi")
    {


    float roty = Input.GetAxis("Mouse Y") * rotSpeed * Mathf.Deg2Rad;
    float rotx = Input.GetAxis("Mouse X") * rotSpeed * Mathf.Deg2Rad;


    transform.Rotate(Vector3.up, roty);
    transform.Rotate(Vector3.right, rotx);
    }
    else
    {
    rectTransform.anchoredPosition += eventData.delta / canvas.scaleFactor;
    }
    }
     
    Last edited: Jul 28, 2020