Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

If I assign an Object as GameObject, I cant get the RectTransform to work. How to fix that?

I want to give my Parent GameObject Inventory spicific rec-coordinates via this line of code:
Inventory.GetComponent<RectTransform>().position = new Vector3(500f, 0f, 0f);

In the editor, the object Inventory is assigned as a GameObject, so it keeps changing the rec-coordinates to world-coordinates. I’ve tried assigning the Inventory as a Transform and RectTransform but it says that there is a missmatch in the type.

How can I fix that, either by fixing my code or by assigning it as something different?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You should modify the RectTransform’s localPosition:

Inventory.GetComponent<RectTransform>().localPosition = new Vector3(500f, 0f, 0f);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading