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

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. Unity - Scripting API: SpriteRenderer.sprite

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.