USING UNITY JAVASCRIPT. CONVENTIONS AND SYNTAX IN JAVASCRIPT Case Sensitivity All keywords like var or function must be in lowercase. All variable names,

Slides:



Advertisements
Similar presentations
CMPT 100 : INTRODUCTION TO COMPUTING TUTORIAL #5 : JAVASCRIPT 2 GUESSING GAME By Wendy Sharpe 1.
Advertisements

ECMM6018 Enterprise Networking For Electronic Commerce Tutorial 4 Client Side Scripting JavaScript Looping.
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
Internal Documentation Conventions. Kinds of comments javadoc (“doc”) comments describe the user interface: –What the classes, interfaces, fields and.
INNER WORKINGS OF UNITY 3D. WHAT WE ARE GOING TO COVER Intro to Unity Physics & Game Objects Cameras & Lighting Textures & Materials Quaternions and Rotation.
IT151: Introduction to Programming
1 HCI 201 JavaScript - Part 1. 2 Static web pages l Static pages: what we have worked with so far l HTML tags tell the browser what to do with the content.
1 Outline 13.1Introduction 13.2A Simple Program: Printing a Line of Text in a Web Page 13.3Another JavaScript Program: Adding Integers 13.4Memory Concepts.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
PHP Intro/Overview Squirrel Book pages Server-side Scripting Everything you need to know in one slide 1.Web server (with PHP “plug-in”) gets a.
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
Overview of C++ Chapter 2 in both books programs from books keycode for lab: get Program 1 from web test files.
XP Tutorial 1 New Perspectives on JavaScript, Comprehensive1 Introducing JavaScript Hiding Addresses from Spammers.
Testing a program Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines Run time errors:
Introduction to scripting
An Introduction to C Programming Geb Thomas. Learning Objectives Learn how to write and compile a C program Learn what C libraries are Understand the.
Chapter 3 Getting Started with C++
Programming with JavaScript (Chapter 10). XP Various things Midterm grades: Friday Winter Career Fair – Thursday, April 28, 2011 (11 am to 3 pm). – MAC.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Bridges To Computing General Information: This document was created for use in the "Bridges to Computing" project of Brooklyn College. You are invited.
CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad GM-IT CIIT Islamabad CIIT Virtual Campus, CIIT COMSATS Institute.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
HOMEWORK REVIEW This is an if else statement layout if (condition) { code to be executed if condition is true; } else { code to be executed if condition.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
Introduction to JavaScript Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 1.
Computer Science 101 Introduction to Programming.
C Derived Languages C is the base upon which many build C++ conventions also influence others *SmallTalk is where most OOP comes Java and Javascript have.
Web Games Programming Unity Scripting Fundamentals.
Introduction.  The scripting language most often used for client-side web development.  Influenced by many programming languages, easier for nonprogrammers.
A First Simple Program /* This is a simple Java program. Call this file "Example.java".*/ class Example { // Your program begins with a call to main().
JavaScript Syntax and Semantics. Slide 2 Lecture Overview Core JavaScript Syntax (I will not review every nuance of the language)
EIW - ASP Introduction1 Active Server Pages VBScript.
USING UNITY JAVASCRIPT. CONVENTIONS AND SYNTAX IN JAVASCRIPT Case Sensitivity All keywords like var or function must be in lowercase. All variable names,
CS346 Javascript -3 Module 3 JavaScript Variables.
Applications Development
Strings, output, quotes and comments
JavaScript Syntax, how to use it in a HTML document
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
 2000 Deitel & Associates, Inc. All rights reserved. Outline 8.1Introduction 8.2A Simple Program: Printing a Line of Text in a Web Page 8.3Another JavaScript.
Problem Solving Methodology Rachel Gauci. Problem Solving Methodology Development Design Analysis Evaluation Solution requirements and constraints. Scope.
1 Server versus Client-Side Programming Server-SideClient-Side.
Python Let’s get started!.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Agenda Comments Identifiers Keywords Syntax and Symentics Indentation Variables Datatype Operator.
Python 1 SIGCS 1 Intro to Python March 7, 2012 Presented by Pamela A Moore & Zenia C Bahorski 1.
JavaScript Syntax Fort Collins, CO Copyright © XTR Systems, LLC Introduction to JavaScript Syntax Instructor: Joseph DiVerdi, Ph.D., MBA.
1 JavaScript and Dynamic Web Pages Lecture 7. 2 Static vs. Dynamic Pages  A Web page uses HTML tags to identify page content and formatting information.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Behavior trees & The C# programming language for Java programmers
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Overview of c# Programming
Pamela Moore & Zenia Bahorski
Data types and variables
Variables, Expressions, and IO
Exploring JavaScript Ch 14
Getting Started with C.
Chapter 10 Programming Fundamentals with JavaScript
A second look at JavaScript
WEB PROGRAMMING JavaScript.
PHP Intro/Overview Bird Book pages 1-11,
T. Jumana Abu Shmais – AOU - Riyadh
For this assignment, copy and past the XHTML to a notepad file with the .html extension. Then add the code I ask for to complete the problems.
Tutorial 10: Programming with javascript
C Programming Language
SEEM 4540 Tutorial 4 Basic PHP based on w3Schools
Presentation transcript:

USING UNITY JAVASCRIPT

CONVENTIONS AND SYNTAX IN JAVASCRIPT Case Sensitivity All keywords like var or function must be in lowercase. All variable names, function names and identifiers are case sensitive. The following two variables are separate and independent of each other: var Test = 6; var test=4; Test and test will not be classified as the same variable and will cause a Javascript error Whitespace Like most programming and scripting languages, Javascript requires one space between keywords, names and identifiers. Extra spaces are ignored so you can use tabs and spaces wherever you need to make your code easier to read and debug Semi-colons Every line of Javascript must end in a semi-colon ; Blank lines don't need sem-colons.

Comments You can add in comments to help yourself keep track of parts of script. This does not effect the script itself and is not visible // this is a single line comment /* this is a multi-line comment */ Identifiers (Variable names, function names, labels.) The first character in an identifier name must not be a digit. Some key words include: Variables Declare variables using the keyword var. Javascript variables have no explicit data type and can contain data of any type. var mynumber;

EXAMPLE 1- HELLO WORLD This is a basic script. Create a new JavaScript script in Unity. Copy and paste the code and click save. #pragma strict function Start () { Debug.Log (“Hi my name is”); Debug.Log (“Welcome to programming”); } Create a new empty GameObject and attach the script to it. If you get stuck get the link to Tom’s demonstration.

EXAMPLE 2- MATH #pragma strict var num1 : int = 3; var num2 : int = 4; var num3 : int; var displaytext : String; //empty for now function Start () { Debug.Log("Number 1 = " +num1); Debug.Log("Number 2 = " +num2); num3 = num1 + num2; Debug.Log("Number 1 + Number 2 = " +num3); }

EXAMPLE 3- CHANGE COLOUR (IF STATEMENTS) #pragma strict function Start () { } function Update() { if(Input.GetKeyDown(KeyCode.R)) { gameObject.renderer.material.color = Color.red; } if(Input.GetKeyDown(KeyCode.G)) { gameObject.renderer.material.color = Color.green; } if(Input.GetKeyDown(KeyCode.B)) { gameObject.renderer.material.color = Color.blue; }

IF ELSE STATEMENTS scripting/if-statements This is more advanced, but you will get an understanding of the importance of if, else statements

FOR LOOPS FOR LOOPS through a block of code a number of times. Format: (set initial variable; condition; action on the variable) (rules, action)

EXAMPLE 4- LOOPING (FOR) #pragma strict var numEnemies : int = 3; function Start () { for(var i : int = 0 ; i < numEnemies ; i++) { Debug.Log("Creating enemy number: " + i); } (set initial variable; condition; action on the variable)

EXAMPLE 5- ROTATE OBJECT #pragma strict var variableRotationRate = 0.0f; var fixedRotationRate = 0.0f; function Update () { transform.Rotate( Vector3.up * Time.deltaTime * ( variableRotationRate * 360.0f ) ); } function FixedUpdate() { transform.Rotate( Vector3.up * Time.deltaTime * ( fixedRotationRate * 360.0f ) ); }

C# VS. JAVASCRIPT SYNTAX If you are planning to continue on creating the game, I suggest you listen carefully at the difference between C# and JavaScript, as we are learning JavaScript yet all scripting in the game is in C#. scripting/c-sharp-vs-javascript-syntax