Here we'll look at Input.GetMouseButtonDown() as its both straightforward and representative of the wider uses of Input.
In this case we'll simply use Input.GetMouseButtonDown() to print a message to the console to say that the message has been received by the computer.
It should be noted that there are two other very similar commands: GetMouseButtonUp() and GetMouseButton() which have subtly different applications and requirements; whilst GetMouseButton() detects whether or not the mouse is currently pressed down, GetMouseButtonDown() detects if it has been pressed down.
In practice this is the difference between rapid fire, in the case of GetMouseButton(), and single fire in the case of GetMouseButtonDown(). GetMouseButtonUp() detects if the mouse click has ended, for example at the end of a mouse drag.
The last thing to bear in mind is that when using MonoBehaviour the function should be used in the Update() method as this is called every frame. In effect the code makes the software check every frame whether or not the statement is true.
Step by step then the Input.GetMouseButtonDown() functionality is used as follows:
There is a lot more to Unity's Input class of course; it handles any kind of input from keyboards, mice, accelerometers, microphones... indeed any kind of Input data at all.
For much more information check out Unity's online manuals, and of course don't forget to have a look at the Complete Unity Developer course where Ben and Brice teach this and a whole lot more.
Hi, my name is Tom, I'm a student on the Complete Unity Developer course and thanks to Ben and Brice I've learnt an incredible amount in a really short time.
Just a few short weeks ago I was tentatively printing out lines to console and now I am confident enough to be starting out on a project of my own!
I'm helping write these blogs partly to share my exuberance about all the things that I'm learning, but mostly to help me crystallise the information in my own mind :)
If you're curious, check out my blog about my first solo project Food Cart Express, where I'll be sharing the ups and downs of the development cycle as seen by a one-man show on his first program.
There'll be a lot of hair being pulled out as I struggle with crowd control algorithms, menu systems and misplaced mouse clicks, but I hope the occasional cheer as I *finally* work out how to keep persistent menu contents throughout the game!
In any case, it's there for you to look at, either to watch the development cycle in all its guts and glory and learn from it or to point and laugh!