How to move recttransform by script?

I have panel UI, that is title object.

When I work at unity, I want it not hinder camera, so I made its position as (-2000, -2000, 0).

But when game start, it should become center of game screen, but how move it by script?

I tried like
titlePanel.transform.localPosition = new Vector3(0, 0, 0);

but nothing happen. I don’t know why unity doesn’t allow it. Very upset.

If the ui is annoying you in the scene view, you can hide and lock the content of the ui layer.
To do so open the layers drop down in the top right of the unity main windows and select the hide / lock icon.

@leegod

Hi, just use rectTransform instead of typical transform, as it replaces Transform component in UI GameObjects - and it’s meant to be used when working with canvas system:

void Start ()
{
    this.GetComponent<RectTransform>().localPosition = Vector3.zero;
}
2 Likes

This does not work…

Sorry, it works. I had problem at other script’s code before it reaches above. Now it works.

transform.localPosition works on ui components as well. But it appears OP had another bug in their code, so they got that fixed. (And considering RectTransform inherits from Transform anyways).

Normally I would only use RectTransform if I needed the additional things that come with it.

@Brathnann

Yes you are correct, I was thinking about saying something about that, but left it out.

Also, I didn’t say it didn’t work and neither did I see his code to be able to know if he had problem elsewhere.

You can use inherited functionality from Transform component in RT or use those features from Transform itself but if you instruct someone to use transform with UI items, then they are not going to (maybe) be aware of RT features like anchorMax, anchorMin, pivot and so on… which are not available in Transform.