Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved Disable scaling when zoom in or out

Discussion in 'UGUI & TextMesh Pro' started by kekikcilerakin, Mar 25, 2021.

  1. kekikcilerakin

    kekikcilerakin

    Joined:
    Dec 11, 2015
    Posts:
    4
    I have this button on a world space canvas and whenever I zoom in our out it scales as how it supposed to. But how can I make it so it doesn't scale? Gif below:
     
  2. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,073
    Don't use an world space canvas. Use a camera canvas and then calculate the position where to display your ui.
    To do that, place an empty game object at the location you want the UI to be attached to.

    then create a script which does in the update method something like this:
    Code (csharp):
    1.  
    2. Vector2 pos = myCameraCanvas.worldCamera.WorldToViewportPoint(myReferenceObject.transform.position);
    3. myUiRectTransform.anchorMin = pos;
    4. myUiRectTransform.anchorMax = pos;
    5.  
     
    kekikcilerakin likes this.
  3. kekikcilerakin

    kekikcilerakin

    Joined:
    Dec 11, 2015
    Posts:
    4
    Dude you are awesome, thank you! Just one more thing, right now when I move camera around the button follows it's position delayed like it's not fixed in that position, is there a way to do this look fixed just like in word space canvas?
     
  4. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,073
    try changing the script execution order of your script to a negative value. (Edit -> Project Settings -> Script Execution Order -> add your script (plus button) -> drag it above the default time)

    EDIT: maybe you need it after default time... just try both options (before & after default time) and document here if one of the options solved your problem :)
     
    Last edited: Mar 25, 2021
  5. kekikcilerakin

    kekikcilerakin

    Joined:
    Dec 11, 2015
    Posts:
    4
    Unfortunately neither of those worked :( Thank you for helping me though!