Moving GameObject by it RectTransform

7619464--947329--imagen_2021-11-01_083616.png.268b998e31b75ff7dfb146f8c8285697.png

Hi everyone!

I’m trying to code a game like hearthstone. Every time the player earns a new card I instatiate a “carta” (card) prefab with the hierarchy shown in the image.

I would like to instatiate every earned card a little bit to the right of the previous card but when I try to move the GameObject transform.position nothing happens, because it has a canvas I guess.

Because of that I’m trying to move the card by the child panel RectTransform, But I don’t know how to do it via script and if it’s the best way to do the thing that I want.

Any help is welcome.

The translation of the image is: Card-Canvas-Card Panel-Mask-Image-Card frame-Description-Bottom left text-bottom right text-card title text

This is the correct way to go.

It won’t be because of the canvas.

It might be because you have a layout item driving its position however.

Be sure you do NOT use magical numbers for anything in UI because at different resolutions and aspect ratios, your layout will become incorrect. Instead always use anchors and invisible objects placed in scene to drive positions, spacings, etc. dynamically.

But even when i try to move the transform of the gameObject directly in the inspector or game scene it won’t move anyway (when the game is running)

Then something else is moving it. Are there animations going on? Those usually win this sort of battle unless you use IK callbacks.

I found a solution, just changed the canvas render mode to World Space. I don’t know if it’s the best option but it’s working!

I was just looking at this on friday, as I had forgotten the inspector for the RectTransform changes what it displays based on what it thinks makes it easier to edit manually, and what it shows aren’t actually accessible fields. If you set the inspector to Debug mode, you get a better view of what is happening and what you can edit. But you’re probably going to be looking at RectTransform.localPosition.