Search Unity

Moving Canvas elements is screwy, debug and inspector saying different things.

Discussion in 'Getting Started' started by Tset_Tsyung, Jun 14, 2017.

  1. Tset_Tsyung

    Tset_Tsyung

    Joined:
    Jan 12, 2016
    Posts:
    411
    Hey all,

    Okay, so I'm working on a simple moving UI system for a retro style game (title comes down, stops, "insert coin" starts flashing.)

    I've set the image anchor and pivot to centre top, moved image to -450 (so that in the scene view it's above the camera's view.

    In code I'm using recttransform.translate to move it downwards. I'm checking recttransform.position.y to see when it gets to it's desired location so that I can move on to the next bit of the 'intro'. However, even though the recttransform in the insector reads -90 (or below - therefore hitting my threshold) the debug of recttransform.position.y still reads about 500. In fact, as soon as I start my game the debug reads the y pos as 802.2.

    I have the canvas scaler set to "Scale with screen size", would this be the cause of the screwy behaviour?

    WHAT'S MORE: if I set the position manually in code it throws the image WWWAAAYYYY off to the left.

    Thoughts?
     
  2. Tset_Tsyung

    Tset_Tsyung

    Joined:
    Jan 12, 2016
    Posts:
    411
    Okay, so 24 hours later I think... THINK I have a solution.

    Basically, I should've been using rectTransform.localPosition and NOT rectTransform.position as I was. This means that the anchors are not ignored. However the position values were still quite off, not sure about those.

    So I simply took measurements on the fly and adjusted my initial and final values too match that debug was throwing out along the way. Still don't know why those values were different... but NVM, got it working in the end...