2.5D Platformer — Collectables #12
No Animations needed! Just code!

One thing I noticed through Game Dev forums, videos, and tips is that not always a GameObject has to have an animation. Instead, code is used to be mixed with complex animations or to increase performance by avoiding the Animator (specially on UI).
So, I’ve decided to manually code a simple animation for a collectable in my prototype!
Simple Move and Rotate
For the collectable, I want it to go up and down. The simplest way to do this is to use Sine waves, and adjusting the values of the frequency and amplitude to my liking.

I also want it to rotate around the Y axis. With transform.Rotate and a Speed variable, it’s more than enough.

Collecting
As of right now, I don’t have a manager to track the collectables picked up by the controller. I would need to create a new Singleton script and send a pick-up event to it.
Either way, just using a Trigger Collider and OnTriggerEnter, that’d be enough to trigger the event which I set to just deactivate the Collectable GameObject.

Result
