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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Move RectTransform according to Screen

Discussion in 'Scripting' started by dccoo, Mar 27, 2018.

  1. dccoo

    dccoo

    Joined:
    Oct 3, 2015
    Posts:
    161
    Suppose I have an UI Image in the center of the screen (say (width/2, height/2), but I don't remember now if RectTransform consider (0,0) as the center).

    How should I do (for example) to move the image so that its center is (0, height/3) ?
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
  3. dccoo

    dccoo

    Joined:
    Oct 3, 2015
    Posts:
    161
    obviously I found that, I wouldn't be asking if I hadn't gone through some searching, I even ran over all the discussion between localPosition vs anchoredPosition usage, but I couldn't move the RectTransform according to the screen (as I asked) correcly
     
  4. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Are you simply asking for? :
    Code (csharp):
    1. GetComponent<RectTransform>().anchoredPosition = new Vector3(0, Screen.height/3);
     
  5. dccoo

    dccoo

    Joined:
    Oct 3, 2015
    Posts:
    161
    I had tried this before but the RectTransform was moving strangely (I think it didn't move enough although it moved the correct direction vector), do you know any constant that could be generating the problem?
     
  6. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    well, the anchored position is between the anchors and the pivot, so perhaps you had different settings?
     
  7. dccoo

    dccoo

    Joined:
    Oct 3, 2015
    Posts:
    161
    I'm trying to move an image that is full screen and anchored to fully stretch.
     
  8. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    I'm not sure what to suggest next...