So I spent some time today trying to make something look pretty! I realize at this point its a bit wasted effort, but I had a blast. I was able to make a somewhat satisfying coin collection animation using unity’s animator, as well as simply adding a basic counter to the UI canvas.
EDIT: https://www.youtube.com/watch?v=Geb-HwBExdQ
Particle Systemsssss
So I am slowly starting to understand how particle systems work finally! I was able to create the star animation quite easily! This is what it looks like up close.
So basically all I had to do to create this was a few settings in the particle system of unity.
The biggest thing was just setting the renderer to the mesh that I made in blender! Once you do that, the particles take on the shape of the renderer, and it’s easy to play with the settings from there. Sadly, this took me quite awhile to realize so I was pretty happy I figured that out today.
Also, I’m not controlling the particle system at all in terms of the code! It just plays on loop until the disabling of the game object.
Rotation and Collection!
So the rotation was quite simple. Just one line of code.
Basically all this is doing is rotation around itself, on the y axis (vector3.up) by 1 degree. This fires in update so you can adjust that value, I found leaving it at 1.0f was a nice rotation. Next thing I plan to do is find a random number at a suitable speed range and use that so they don’t all rotate at the same pace.
Collection Script
This was pretty standard straight forward. I haven’t written my object pooling system yet, so this is just using destroy, but I am aware of this being bad practice! All I’m doing for collection is quite simple:
So what I’m doing here is just getting the animator component. I’m using it to then call the animation I want. And after that is kicked off I’m starting a co-routine. I changed it to this method as it makes it so the animation plays out nicely before the game object disappears. I had it inside the same method before, and the animation wasn’t even playing.
In the co-routine I’m just:
- Setting a bool to ensure I only ever call the coroutine once.
- Setting the coin count in my data manager class.
- Setting the GUI update for coin collection
- Destroying the object.
And for #4, that will be replaced with my object pooling functionality.
Animation
Still trying to get a hang of this animator. What I ended up having to do for this animation was create an empty game object, and make it the parent of the coin mesh itself. I applied all the animations to that core game object, moving the coin and recording the parent’s transform. This allows the animation to remain the same no matter where you put the object (Just ensure you are using root motion!).