Search Unity

Image Flipping when clicked.

Discussion in 'Scripting' started by ErmergerdEnt, Oct 2, 2019.

  1. ErmergerdEnt

    ErmergerdEnt

    Joined:
    Apr 7, 2017
    Posts:
    54
    My UI image keeps flipping when i try and drag to rotate it.

    Code (CSharp):
    1. public void OnDrag(PointerEventData eventData)
    2.     {
    3.      
    4.         Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    5.         mousePos = mousePos - target.transform.localPosition;
    6.         angle = Mathf.Atan2(mousePos.y, mousePos.x) * Mathf.Rad2Deg;
    7.  
    8.         target.transform.localRotation = Quaternion.Euler(0, 0, angle);
    9.  
    10.     }
    im not sure why. but as you can see i have a Empty GameObject. A UI image is attached to that, with another Ui Image that is the border, the border then contains 2 more images. One rescales the object and the other for rotating. The rotating image has the above code attached to it. The target is the StickerPrefab itself that serves as the parent of the other images.



     
  2. ErmergerdEnt

    ErmergerdEnt

    Joined:
    Apr 7, 2017
    Posts:
    54
    StickerPrefab -> The Parent
    Sticker -> The actual sticker
    BorderHolder -> The Dotted border.
    Rotator -> Used to rotate
    Rescaler -> used to scale up and down