I have a quick question. If anyone can answer me, I will be grateful. I want to make an animation for about 117 cubes. I know that I don't need to do it one by one. I can simply make a prefab for the cube and duplicate it, but the problem is I just want to make it for the z-axis. However, the animation applies it for all the position properties. So how can I make an animation for the z-axis without affecting y and x? Thank you.
-
Mark the z as the only property to record? – BugFinder Jan 19 '21 at 19:05
-
I tried to, but it still applies for all the Position properties – mohaker Jan 19 '21 at 19:12
-
You essentially MUST use the (incredibly useful) Animation system in Unity. once you spend 10 mins with it, it is dead easy and you will thank your stars you changed over to it. – Fattie Jan 19 '21 at 23:57
2 Answers
The problem is that you are animating the cubes based on the world position, so it is teleporting everything even for x axis and y axis.
You can easily avoid this by adding your prefab with the animation inside an empty gameObject, you can save it as a prefab too. In this way when you instantiate the empty with inside the cube, the child object (your cube) will move based on the empty position, so y and x will be the x and y of the empty one.
So
1 animate your cube
2 add the cube to an empty game Object
3 set your empty as prefab and duplicate it

- 1,194
- 3
- 8
- 21
-
while this is true, in all cases for years now you should simply use the (wonderful) Animator in Unity. once you take 10 minutes to get how it works, all of these issues disappear forever. – Fattie Jan 20 '21 at 00:00
-
Btw, does it work if i want to move the x and y from the place they are placed in to one specific location – mohaker Jan 20 '21 at 08:43
If your animation is not sprite based, only transform based, you can use TWEENING Libraries. LeanTween is in the Unity Asset Store as free asset. It is far much faster than builtin unity animation. It is really easy to use. I used it in over 100 UI objects and it didn't even used any remarkable resource at all (FOR 2D Object). I believe that will solve your problem easily.

- 600
- 1
- 6
- 14
-
(1) never, ever use "tweening" for animations these days. do it the dead easy way - take 10 minutes to learn Unity's fantastic Animation system. – Fattie Jan 19 '21 at 23:58
-
(2) never use a "tweening library", they are the most useless things going, they don't work, and they were useful maybe 20 years ago. if for some reason you must tween, just use a tweeng extension. (example https://stackoverflow.com/a/37228628/294884 ) it's one line of code. – Fattie Jan 19 '21 at 23:59
-
Why tweening library is bad, many professional developer is use it too. It is really flexible, far easy too prototype and far less use resource. Also unity's animation system is good but not even close to fantastic. Try and start hundreds of ui animation on Unity bultin animation system and play on Mobile. Then you will agree – SeLeCtRa Jan 20 '21 at 01:29
-
-
LeanTween is a fantastic tool. And you should avoid to use Unity Animator for UI, because your whole Canvas gets updated every single frame as long as that Canvas or its Children only **holds** an Animator Component, without even playing the animation. This can have a big performance impact, depending on the size of your UI / Canvas. In conclusion: If you want to use the Animator for UI, or for UI-optimization in general, it is highly recommended to look into [Nested Canvases](https://learn.unity.com/tutorial/nested-canvas-optimization-2019-3?uv=2019.4#). – Vivien Lynn Feb 09 '21 at 08:57
-
For general optimization: [Optimization tips for Unity UI](https://unity3d.com/how-to/unity-ui-optimization-tips). – Vivien Lynn Feb 09 '21 at 09:00