In this tutorial, we will learn how we can control our dinosaur inside the game. Also, we will get familiar with the concept of Scripts, Predefined methods, Vectors, and the basic input methods in Unity.
Primary Predefined methods
- Start - The Start method is called only once at the begining of execution of the script.
- Update - The Update method is called on each and every frame till the script is getting executed.
Vectors
There are two types of vectors in Unity - Vector2 & Vector3. Vector2 holds two values (x & y) and Vector3 holds 3 values (x, y, & z).
Basic Input Methods
-
Using Keyboard - To use the keyboard to provide input in our game;
We can use Input.GetKeyDown(Keycode) to get the input from any specific keyboard key, where Keycode is a string defining the pressed key. For example, Input.GetKeyDown("space") will take input from the Spacebar key.
-
Using Mouse - To get input through mouse;
We can use Input.GetMouseButtonDown(Keycode) to get input from a mouse button click where Keycode is a number from 0 to 2 signifying the left, right, & middle mouse button. For example, Input.GetMouseButtonDown(0) will take input from left moue button.
Now without any further ado, let's watch the video.