Hi all,
this might be a beginner question for most of you, but after a whole afternoon of googling, reading and trial & error I’m out of ideas. I am fighting with Unity transforms, and at least for a beginner like me, it’s a night mare since the objects all have “relative” coordinates instead of fixed ones (and most likely, I maybe didn’t set up everything correctly). Please take a look at the enclosed image.
I have a Grandchild (child of a child) object, named “MainMenuButtons”, it’s a empty gameobject that I used to group together some buttons. This group of buttons is animated, and when the scene first loads, I need to play the “load animation” (they start in the position of the “Spawner_MainMenuButtons” and then grow to the virtual screen that is seen in my canvas… but for a smooth animation, I need them to go in their invisible and microscaled start position (the spawners position). I could totally avoid all this trouble if I just simply set the initial transform that way in the scene view, but I need these things visible in the scene view to work with them (at least for now), so I have to have them stay in normal size.
So, I want to use the script to move them in their hide position by changing their transform position and scale.
The logs show, my code actually works, but the math is wrong, I think it’s calculating everything in world coordinates, and not the “local of the local of the worldspace” if you know what I mean.
Can someone please help me out here ? I goggled a lot and found, that there is something called “localPosition” for the child, but it’s not working either.
In the Image you can see the canvas at 0,0,0, the Spawner_MainMenuButtons on it’s own Transform, and then the MainMenuButtons (which has only a normal transform, and no Rect Transform for whatever reason).
I need to move the MainMenuButtons-Object to the LOCAL coordinates that are displayed in the lower right (z-values can remain unchanged). The logs show, the code is being executed , but it uses a wrong coordinate system.
The code in question is this method:
In Start, I use :
Transform mainMenuBlock = transform.Find("MainMenuButtons");
and later the method:
void HideMainMenu()
{
Debug.Log("I'm inside the Hide Method");
Debug.Log(mainMenuBlock.transform.position);
mainMenuBlock.transform.localPosition = new Vector3(20f, -70f, transform.position.z);
mainMenuBlock.transform.localScale = new Vector3(0.01f, 0.05f, transform.localScale.z);
Debug.Log("New:" + mainMenuBlock.transform.position);
Thank you in advance for helping me out here.
(P.S. Ignore the red errors, it’s just a missing singleton since I didn’t started in the correct scene)