A coin label component completely uı toolkit based, it has animation when add and subtract coins 🤑
- Open the scene, create a new UI Document object by Right Click > UI Toolkit > UI Document
- Select Panel Settings and Source Asset (uxml file) of UIDocument component on the inspector (Demo Panel Settings and Demo.uxml for my case)
- Attach CoinLabelController.cs to the UI Document object. This script will create 10(default of mine) coin sprite and place in VisualElement#CoinArea(a visual element named as CoinLabel in Demo.uxml in my case).
- Open Demo.uss, copy all its content and paste somewhere of your uss file.
- Open DemoGameManager.cs and copy the methods(AddCoin,SubtractCoin), copy the variables and events. In brief, copy all its content, paste them to your own GameManager script(or equivalent script of yours).
- Call DemoGameManager.AddCoin(5) where you want to gain 5 coins. DemoGameManager.SubtractCoin(5) to remove 5 coins