Hi,
I would love to get some input from the community ...
I need to create a numpad with 10 buttons. I have created a button prefab as follows : btnRoot (empty gameobject) > child btn (mesh + collider + animator) > grandchild btnDisplay (sprite renderer)
The sprite renderer uses a spritesheet with the numbers 0-9 on it.
I've also created 2 animations : default (btn upstate) & push (btn up > down > up) with a trigger transition.
If I put a hotspot on the btn, as well as a component variable, link it to a scene asset list, and hit 'play', I can push the button, watch the animation play, and see the variable update from 0 -> 9 and back to 0.
But how to I update the button display (update the sprite renderer) ??? My intention was to use the component variable to select the sprite from the spritesheet.
Thanks !
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
As this is a visual issue, can you share screenshots? I'm not 100% clear on the issue. Is this because using a shared Animation causes each button to have the same number on it?
If you're animating the button being pushed down, generally I'd say the options are:
I have a lot of these kinds of puzzles in my game, so I want to make use of prefabs as much as I can.
My question is really that I can't find a way to change the sprite displayed on the button.
IMAGE :
ibb.co/YLHbzhD
It's a bit tedious, given the 10 digits involved, but you can create a sub-layer in your Animator that has 10 animations that each assign a different sprite. Hook these up to a new Integer Animator parameter that represents the button's value.
Once done, you can then make use of the Link Variable To Animator component, which automatically synchronises your Component Integer variable value with that of the Integer Animator parameter.
Since all buttons work the same way, you can use the same Animator Controller for each of them.