Unity Scripts
BEGINNER
Creating and attaching a script
How to create a script How to add a script
• From Project panel • From project to hierarchy panel,
• Right click drag and drop to the game
• Create object
• C# Script
• In the inspector
• Select the Game Object
• At the bottom, Add Component •It´s already attached
• Write the desired script name
• Click on create and add
Script as a behaviour component
Variables and functions
Variable: box that contains information
Different Type of info: Different Type of box
Variables and functions
Function: Is like a “machine” that processes “boxes” content
Conventions and syntax
Update and FixedUpdate
Update FixedUpdate
Called every frame Called every physics step
Frame time varies Intervals are consistent
Movement of non physic obj Adjustin physics (Rigidbody) objects
Simple timer
It´s Good practice to use forces for
Input movement
Vector
Vector Moving object has a velocity
Velocity:
Denotes a position in space
Change in position/time
relative to origin (0,0)
Position 1 is 5,6
Velocity is 12,5 /hour
What is the new position after 1 hour?
Add currentPosition to velocity Vector