2d game - animation - drinking/glass
Hi,
I am trying to make a 10 second game, the main function is that the player will need to consume a glass of drink. How do I animate this glass to be drunk via a left click. I have sprites for 0/4, 1/4, 2/4 & 3/4. If the player clicks once, then I want it to consum 1/4 or they hold it they consume the whole glass.
I've looked at other questions for mouse click but either I'm getting it wrong by not understanding. I have watched some youtube videos but the interface layouts they use is before 2019.4.9fi
Answer by outramjamie_unity · Oct 30, 2020 at 07:14 PM
The simplest way would be to write a MonoBehaviour script attached to the drink that takes an array of sprites (assignable in editor) and changes the SpriteRenderer.sprite when clicked. https://docs.unity3d.com/ScriptReference/SpriteRenderer-sprite.html
There's a number of mouse events in MonoBehaviour which are called when the objects attached collider component is clicked, OnMouseDown(), OnMouseUp() and OnMouseExit() are the three you probably need. You can use InvokeRepeating to repeatedly call a drink function whilst held and CancelInvoke() in the OnMouseUp/OnMouseExit to stop drinking.
Your answer
![](https://koobas.hobune.stream/wayback/20220613014907im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Help with making interactive text animation for a 2D game 0 Answers
I can't see my animated 2D character in "Scene view" 1 Answer
Problem with Jump Animation 0 Answers
Animation Panel: how to turn an existing loop into just a standing sprite and then implement it 0 Answers
Player should turn in the direction the player is running. (2D Game) 0 Answers