WOODIWISS.MEFreelance Web Developer & Lecturer in the Winchester, Hampshire area.
UnityScriptThe Basics
WOODIWISS.ME
ECMAWhat/Who is ECMA?
• European Computer Manufacturers Association.
• Non-profit Standards Organisation.
• Introducing ECMAScript!
WOODIWISS.ME
ECMAScript
JavaScript.js ActionScript.as
ECMAScript.esLanguage
Dialects
WOODIWISS.ME
Onward!
• NewBehaviourScript.js
• Basic starting point.
• #pragma strict?
• Start
• Update
WOODIWISS.ME
WOODIWISS.ME
WOODIWISS.ME
WOODIWISS.ME
Start()
• gameObject = Cube
• Start = run before first frame.
• e.g set color, set size, set position…
WOODIWISS.ME
Start()
• gameObject = Cube
• Start = run before first frame.
• e.g set color, set size, set position…
WOODIWISS.ME
Start()
• gameObject = Cube
• Start = run before first frame.
• e.g set color, set size, set position…
WOODIWISS.ME
Update
• gameObject = Cube still.
• Continually polling the code. Each frame.
WOODIWISS.ME
Mono Madness
• All scripts extend MonoBehaviour.
• Awake()
• OnCollisionEnter()
• FixedUpdate()
• LOTS more base functions.
WOODIWISS.ME
User Created Functions
Keeps your code DRY !D - on’t R - epeat Y - ourself
WOODIWISS.ME
User Created Functions
Keeps your code DRY !D - on’t R - epeat Y - ourself
WOODIWISS.ME
User Created Functions
Keeps your code DRY !D - on’t R - epeat Y - ourself
Defined
WOODIWISS.ME
User Created Functions
Keeps your code DRY !D - on’t R - epeat Y - ourself
Defined
WOODIWISS.ME
User Created Functions
Keeps your code DRY !D - on’t R - epeat Y - ourself
Defined
Invoked
WOODIWISS.ME
VariablesWhat is a variable? !var playerHealth : int = 100; !var playerHealth : int; playerHealth = 100;
WOODIWISS.ME
Basic Data Types
int - Number without decimal place.
float - Number with decimal place.
boolean - Truth value.
String - Text or words, numbers, some symbols.
Vector3 - X Y Z co-ordinates.
GameObject - Object that is present in the Unity Scene.
WOODIWISS.ME
Basic Data Types
int = 17;
float = 5.994;
boolean = true;
String = “Darren”;
Vector3(100,124,55); // x, y, z
GameObject = GameObject.Find("Zombie");
WOODIWISS.ME
Casting
var fingersOnHand : int;
var playerHeight : float;
var powerupActive : boolean;
var playerName : String;
var playerStartLocation : Vector3;
var enemy : GameObject;
WOODIWISS.ME
Casting and Assigningvar playerAge : int = 17;
var playerHeight : float = 5.994;
var powerupActive : boolean = true;
var playerName : String = “Darren”;
var playerStartLocation = Vector3(0,0,0);
var enemy : GameObject;
enemy = GameObject.Find("Zombie");
WOODIWISS.ME
Arguments
• First define required parameters.
• Specify arguments parsed to function.
WOODIWISS.ME
Arguments
• First define required parameters.
• Specify arguments parsed to function.
WOODIWISS.ME
Arguments
• First define required parameters.
• Specify arguments parsed to function.
WOODIWISS.ME
Links / Research• http://en.wikipedia.org/wiki/Ecma_International
• http://en.wikipedia.org/wiki/ECMAScript
• http://www.mono-project.com/What_is_Mono
• docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.html
• http://unity3d.com/learn/tutorials/modules/beginner/scripting
• https://www.inkling.com/read/javascript-definitive-guide-david-flanagan-6th/chapter-8/function-arguments-and
• http://www.sublimetext.com/
WOODIWISS.MEFreelance Web Developer & Lecturer in the Winchester, Hampshire area.
Next TimeScope / Operators / Statements …
WOODIWISS.MEFreelance Web Developer & Lecturer in the Winchester, Hampshire area.
Questions?
Top Related