0% found this document useful (0 votes)
5 views2 pages

Unity Notes

Tutorial on how to use unity for game development
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
5 views2 pages

Unity Notes

Tutorial on how to use unity for game development
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 2

Naming conventions:

Constants- UPPER_SNAKECASE

Events - PascalCase

Fields - camelCase

Functions- PascalCase

funtion params- camelCase

Movement controls:

wasd , left alt , Shift , all mouse buttons

If you want to set the camera to your current screen postions , then select the camera and press ctrl +
shift+F

Update() function runs for each frame.

How to take input from players:

For getting key input ,you can use

Input.getKey or getKeyDown or getKeyUp

getKey returns boolean unless the key is released ,


where as getKeyDown only returns a boolean on the frame the key was pressed.
The all take parameter -> KeyCode._keyname_

YOu can use Debug.log() for printing on console.

Directions -> Vector2 x= new Vector2(x,y);

This Vector2 is a module of UnityEngine.

#Note - For fixing the issue which arise due to pythogoras theorem and results in greater diagonal
distance we normalize the vector using
inputVector= inputVector.normalized;

The script inherits the properties of the object it is attached to . So you can use them to change the
properties of the object. We use "transform" to access the properties like "transform.position".

When dealing with movement logic , always multiply the postion with "Time.deltaTime". deltaTime is the
time elapsed since last frame.

Delta Time is lower for fast frame rates and higher for slow frame rates. Thus by multiplying it with the
speed , the resulting movement is consistent in both the machines having different frame rates.

(Distance = Speed * time) will remain constant as the time is changed between the machines.
You should never make fields public as it can cause unintentional changes from other classes in a
codebase.

YOu can use [SerializeField] to make a private field visible as well as editable in the unity editor.
Eg -> [SerializeField] private float x= 4f;

To make the object look at the direction it is moving, us the "transform.forward" property. assign the
direction you want the object to look at in this.

You can use "Lerp" for smoothness in transorm changes like rotation, movement, etc.

For positons- Lerp


For rotations - Slerp

transform.forward= Vector3.slerp(intial,target,time);

##Confusion in Slerp

Add animation to the visual component and not the logical component. Always seperate the visual and
logical component of a game object.

For Animation , use the Animator component.


Then you have to make a animator controller to add to the animator component.

Watch the video on animator from code monkey.

Make the animation by simply creating animation file in the animation tab (open by window). And then
make transitions like you would in Finite State machines.

You can use "Parameters" to achieve transitions between different animatons.

#Look at ultimate unity overview course by code Monkey

Keep the Logic script and animation scripts seperate.

You can get component of the object to which the script is attached by using
"GetComponent<component_name>();" function.

eg-> Animator animator =GetComponent<Animator>();

#Note- Animator and Animation are two different components. Animation is legacy and was used a long
time ago. Animator is for more complex animations and is modern. Animation is just used for backwards
compatibility.

For setting parameters you can just write

animator.set_data_type(String:name,value);

try avoiding using Strings for identifying things. There can many unnoticeable blunders one can make
because of that.

You might also like