Scripting Newbie guide to Unity Javascript

32
Forum Unity Community Support Scripting Newbie guide to Unity Javascript (long) Log in Home Unity Gallery Asset Store Learn Community Company Download Buy Forums Answers Feedback Evangelism Community Forums All Forums Answers Feedback Today's Posts Search Forum Actions Results 1 to 20 of 110 Page 1 of 6 2 3 ... Last Newbie guide to Unity Javascript (long) This is my introduction to scripting with the Unity version of Javascript, also known as UnityScript. It assumes no prior programming experience. If you have some prior programming experience, you may want to skip ahead to functions and classes. If you're an expert, you'll probably want to avoid this thread entirely, as you'll likely be offended at how much I simplified some concepts! If you want to run the sample code, you do need to be familiar with the Unity interface and know how to create a script Location: USA tonyd Posted: 04:56 PM 11-08-2009 Thread Tools Newbie guide to Unity Javascript (long) http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long) 1 of 32 29.08.2013 07:52

Transcript of Scripting Newbie guide to Unity Javascript

Forum Unity Community Support Scripting Newbie guide to Unity Javascript (long)

Log in

Home

Unity

Gallery

Asset Store

Learn

Community

Company

Download

Buy

Forums

Answers

Feedback

Evangelism

Community

Forums

All

Forums

Answers

Feedback

Today's Posts Search Forum Actions

Results 1 to 20 of 110 Page 1 of 6 2 3 ... Last

Newbie guide to Unity Javascript (long)

This is my introduction to scripting with the Unity version of Javascript, also known as UnityScript.

It assumes no prior programming experience.

If you have some prior programming experience, you may want to skip ahead to functions and classes. If you're an

expert, you'll probably want to avoid this thread entirely, as you'll likely be offended at how much I simplified some

concepts!

If you want to run the sample code, you do need to be familiar with the Unity interface and know how to create a scriptLocation: USA

tonyd Posted: 04:56 PM 11-08-2009

Thread Tools

Newbie guide to Unity Javascript (long) http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long)

1 of 32 29.08.2013 07:52

Posts: 1,223

Newbie guide to Unity Javascript (long) http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long)

2 of 32 29.08.2013 07:52

and attach it to a game object. See links below.

Intro to the Unity Interface:http://download.unity3d.com/support/...Essentials.pdf

Intro to Scripting with Unity - read sections labeled "Our first script", and "Attaching the script".

http://download.unity3d.com/support/...20Tutorial.pdf

Text in RED applies to Unity iPhone users only.

Think of a variable as a container that holds something.

You can choose to name a variable anything you wish, as long as it contains no spaces, starts with a letter (preferablylower case), contains only letters, numbers, or underscores, and is not a reserved keyword.

Use the keyword 'var' to create a variable. Let's call our first one 'box'.

Code:

var box;1.

There you go, you've declared your first variable! If you're wondering about the semicolon at the end, statements

(commands) in Javascript must end in a semicolon.

iPhone programmers, if you declare a variable without setting it to a value, you must state what type the variable is, inthis case String. Common types include String, int, float, boolean, and Array. Note that proper capitalization is necessary!

var box : String;

Of course, our box is empty, so let's set it to a value by adding the following line:

Code:

box = "apple";1.

Newbie guide to Unity Javascript (long) http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long)

3 of 32 29.08.2013 07:52

Now our box contains a text string (variable type), which happens to be "apple".

Note that you can declare your variable and set it to a value in the same statement:

Code:

var box = "apple";1.

But once it's declared, you can't declare it again.

You can, however, change it to another value (as long as the new value is the same type as the original).

Code:

box = "orange";1.

In addition to text strings, variables can hold numbers:

Code:

var number = 10;1.

This is an integer (int), which means whole numbers only... no decimal places.

But we could also do a floating point number (float), which has decimal places:

Code:

var myFloat = 10.5;1.

Variables can also contain booleans. A boolean is simply a true/false value:

Code:

Newbie guide to Unity Javascript (long) http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long)

4 of 32 29.08.2013 07:52

var gameOver = true;1.

We'll discuss these more later.

Notice that a variable can normally only contain one thing at a time. But we can make a variable that contains multiple

things, by creating an array:

Code:

var applePie = Array("apple", "brown sugar", "butter", "pie crust");1.

This variable contains everything you need to make an apple pie!

If we wanted to view the contents of applePie, we could output it to the Unity console using the Debug command. Addthis line to the code above:

Code:

Debug.Log(applePie);1.

On play, the console should display:

apple,brown sugar,butter,pie crust

To access a single element (item) from an array, we can access it thru its index (position in array). This may seem

confusing, but indexes start at 0. So index 0 is actually the first element in the array.

Code:

var applePie = Array("apple", "brown sugar", "butter", "pie crust");1.

var item1 = applePie[0];2.

Debug.Log(item1);3.

Newbie guide to Unity Javascript (long) http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long)

5 of 32 29.08.2013 07:52

You can actually use indexing with Strings as well. The following code displays the first character of "hello", the letter 'h':

Code:

var myString = "hello";1.

Debug.Log(myString[0]);2.

Now lets alter our variables in other ways.

We can add variables:

Code:

var number1 = 10;1.

var number2 = 11;2.

var total = number1 + number2;3.

Debug.Log(total);4.

If you add an int (integer) to a float (floating point number) the result becomes a float:

Code:

var number1 = 100;1.

var total = number1 + 1.5;2.

Debug.Log(total);3.

Obviously, we can also subtract/divide/multiply ints and floats.

Less obvious, we can also 'add' strings. This merges them together:

Code:

var string1 = "apple";1.

var string2 = "cider";2.

var combo = string1 + string2;3.

Debug.Log(combo);4.

Newbie guide to Unity Javascript (long) http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long)

6 of 32 29.08.2013 07:52

If we add a number to a string the result becomes a string.

We can also multiply strings.

Code:

var greeting = "howdy";1.

Debug.Log(greeting * 3);2.

Unfortunately, we can't divide or subtract strings. There are ways to split strings and remove parts of strings, but that is a

more advanced topic.

Let's wrap up our discussion on variables with incrementing numbers (changing their value by a set amount).

First, declare a variable and set it to 1:

Code:

var number = 1;1.

We can increment numbers various ways.

Code:

number = number + 1;1.

The above adds 1 to our number, and it becomes 2.

But programmers are lazy, and decided this was too long. So they abbreviated it to:

Code:

number += 1;1.

Newbie guide to Unity Javascript (long) http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long)

7 of 32 29.08.2013 07:52

This is simply shorthand for number = number + 1;

But guess what? Lazy programmers decided even THIS was to long, and shortened it to:

Code:

number ++;1.

Use whichever makes most sense to you, they all do the same thing! But note that if you choose to increment by a valueother than 1, ++ won't work.

++ is shorthand for += 1 only.

You can also do the same with subtraction:

Code:

number --;1.

But for division and multiplication, you must use one of the longer forms:

Code:

number = number/2;1.

number *= 2;2.

Note that an asterisk means multiply, a slash means divide.

If statements are conditional statements. If a condition evaluates as true, do something.

Newbie guide to Unity Javascript (long) http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long)

8 of 32 29.08.2013 07:52

We can do a comparison of two values by using two equal signs, ==

"number == 10" evaluates as true if our number variable equals 10, otherwise it evaluates as false.

Note: it's important to remember to use two equal signs when comparing variables/values, but one equal sign whensetting a variable to a value!

The following creates a variable and sets it to true, checks to see if the variable equals true, and if so prints a text string

to the console:

Code:

var gameStarted = true;1.

if (gameStarted == true)2.

Debug.Log("Game has started");3.

The above is actually redundant, since our variable 'gameStarted' is a boolean. There is no reason to check "if true

equals true", just check "if true":

Code:

var gameStarted = true;1.

if (gameStarted)2.

Debug.Log("Game has started");3.

If you're wondering why I didn't put a semicolon behind if (gameStarted), it's because technically it is only the first half of

the statement. I could have written it like so:

Code:

if (gameStarted) Debug.Log("Game has started");1.

I could have also written it this way:

Code:

Newbie guide to Unity Javascript (long) http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long)

9 of 32 29.08.2013 07:52

if (gameStarted){1.

Debug.Log("Game has started");2.

}3.

Those brackets represent a block of code, and tell the if statement to execute anything in between... if the condition is

true!

When if contains only one statement to execute, the brackets are optional. But if it contains more than one statement,you MUST use the brackets! Note that semicolons are not needed after brackets.

Code:

var gameStarted = false;1.

If (gameStarted == false){2.

gameStarted = true;3.

Debug.Log("I just started the game");4.

}5.

Read the second line of code above. Remember those lazy programmers? They don't want to write

Code:

if (gameStarted == false)1.

When they can just write:

Code:

If (not gameStarted)1.

But you know what? Why write 'not' when I can shorten that too?

Code:

Newbie guide to Unity Javascript (long) http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long)

10 of 32 29.08.2013 07:52

if (! gameStarted)1.

Yes, an exclamation point means 'not' to lazy programmers!

You can also combine this with equals, where it means "not equals":

Code:

var answer = 1;1.

if (answer != 42) Debug.Log("Wrong question!");2.

You can also check for greater than or less than:

Code:

var age = 18;1.

if (age > 18)2.

Debug.Log("old enough");3.

else if (age < 18)4.

Debug.Log("jailbait");5.

else6.

Debug.Log("exactly 18");7.

Notice the 'else if' and 'else' keywords? if the first if statement condition fails (evaluates as false), it then checks thecondition under else if. If that one fails, it will check the next else if (if one is available), and finally if all conditions fail, it

executes the statement under else. Again, if the 'if', 'else if', or 'else' statements contain more than one statement, eachblock of code must be separated by brackets.

You can also check for multiple conditions in a single statement:

Code:

if (age >= 21 && sex == "female")1.

buyDrink = true;2.

Newbie guide to Unity Javascript (long) http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long)

11 of 32 29.08.2013 07:52

Above, we introduced greater than or equal to >= and the AND operator, which is two ampersand characters: &&. If both

conditions are true, the statement is executed. If even one is false, the statement is not.

Note: if you want to run the above code, remember to create variables for age (int), sex (String), and buyDrink (boolean)first!

Code:

if (engine == "Unity" || developer == "friend")1.

buyGame = true;2.

Above, we used the OR operator, which is two pipe characters: ||. If either condition is true, the statement is executed. Ifboth are false, the statement is not.

Note: if you want to run the above code, remember to create variables for engine (String), developer (String), and

buyGame (boolean) first!

If can also be used with the keyword 'in'. This is generally used with Arrays:

Code:

var names = Array("max", "rick", "joe");1.

if ("joe" in names) Debug.Log("Found Joe!");2.

Looping allows you to repeat commands a certain amount of times, usually until some condition is met.

What if you wanted to increment a number and display the results to the console?

You could do it this way:

Code:

var number = 0;1.

Newbie guide to Unity Javascript (long) http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long)

12 of 32 29.08.2013 07:52

number += 1;2.

Debug.Log(number);3.

number += 1;4.

Debug.Log(number);5.

number += 1;6.

Debug.Log(number);7.

And so on... but this is redundant, and there is nothing lazy programmers hate more than rewriting the same code overand over!

So lets use a For Loop:

Code:

var number = 0;1.

for (i=1; i<=10; i++){2.

number += 1;3.

Debug.Log(number);4.

}5.

Okay, that for statement on the second line may look a little confusing. But it's pretty simple actually.

i=1 -created a temporary variable i and set it to 1. Note that you don't need to use var to declare it, it's implied.i<=10 -how long to run the loop. In that case, continue to run while i is less than or equal to 10.

i++ -how to increment loop. In this case, we are incrementing by 1, so we use the i++, shorthand for i+=1

If we're just printing 1 thru 10, our code above could be shortened. We don't really need the number variable:

Code:

for (i=1; i<=10; i++)1.

Debug.Log(i);2.

Just like if statements, brackets are optional when there is only one statement to execute. Talk about beating a dead

horse...

We can also count backwards:

Newbie guide to Unity Javascript (long) http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long)

13 of 32 29.08.2013 07:52

Code:

for (i=10; i>0; i--)1.

Debug.Log(i);2.

Or print all even numbers between 1 and 10:

Code:

for (i=2; i<=10; i+=2)1.

Debug.Log(i);2.

We could also use a While loop, an alternative to For statements.

While executes repeatedly until a condition is true.

Code:

var number = 0;1.

while (number < 10){2.

number ++;3.

Debug.Log(number);4.

}5.

While loops are most useful when used with booleans. Just make sure the escape condition is eventually met, or you'll be

stuck in an infinite loop and the game will most likely crash!

Code:

var playerJumping = true;1.

var counter = 0;2.

while (playerJumping){3.

//do jump stuff 4.

counter += 1;5.

if (counter > 100) playerJumping = false; 6.

Newbie guide to Unity Javascript (long) http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long)

14 of 32 29.08.2013 07:52

}7.

Debug.Log("While loop ended");8.

Notice the fourth line of code above? The one that starts with two slashes? This means the text afterwards is a

comment, and will not be executed. Comments are useful for noting how your code works for yourself or others, forputting in placeholder text to be replaced later (as above), or for commenting out sections of your code for debug

purposes.

If you thought loops were a time saver, wait until you find out about functions!Functions allow you to execute a whole bunch of statements in a single command.

But lets keep things simple at first. Lets define (create) a function that simply displays "Hello world" on the console.

Code:

function SayHello(){1.

Debug.Log("Hello world");2.

}3.

To execute, or 'call' this function, simply type:

Code:

SayHello();1.

Note the parenthesis after our function. They are required, both when we define our function and call it. Also note that our

function name is capitalized. It doesn't have to be, but capitalizing function names is the norm in Unity.

What if we wanted a function to say different things? We can pass a value, or argument, to the function:

Code:

Newbie guide to Unity Javascript (long) http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long)

15 of 32 29.08.2013 07:52

function Say(text){1.

Debug.Log(text);2.

}3.

Above, text is the argument, a temporary variable that can be used within the function only.

iPhone programmers, you should also state what type the argument is, in this case String.

function Say(text : String){

Now when we call our function, we have to provide an argument:

Code:

Say("Functions are cool!");1.

We can also pass variables:

Code:

var mytext = "I want a pizza";1.

Say(mytext);2.

Another useful thing functions can do is return a value. The following function checks to see if a number is even and if so it

returns true, else it returns false:

Code:

function EvenNumber(number){ //iPhone programmers, remember to add type to arg (number : int);1.

if (number % 2 == 0)2.

// NOTE: % is the mod operator. It gets the remainder of number divided by 23.

return true;4.

else5.

return false;6.

}7.

Newbie guide to Unity Javascript (long) http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long)

16 of 32 29.08.2013 07:52

8.

var num = 10;9.

if ( EvenNumber(num) )10.

Debug.Log("Number " + num + " is even");11.

When the return command is executed in a function, the function is immediately exited (stops running). Returns don't have

to return a value:

Code:

function Update(){1.

if (!gameStarted) return; //exit function2.

}3.

The Update() function above is one of the main functions in Unity. You do not have to call it manually, it gets called

automatically every frame.

Functions can be overloaded. Sounds complicated, but it's really quite simple. It means you can have multiple versions ofa function that handles different types of arguments, or different numbers of arguments.

To handle different types of arguments, simply use the colon : to state the type of argument being passed. Common

types include String, int, float, boolean, and Array. Note that proper capitalization is necessary!

Code:

function PrintType(item : String){1.

Debug.Log("I'm a string, type String");2.

}3.

4.

function PrintType(item : int){5.

Debug.Log("I'm an integer, type int");6.

}7.

Newbie guide to Unity Javascript (long) http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long)

17 of 32 29.08.2013 07:52

8.

function PrintType(item : float){9.

Debug.Log("I'm a float, type float");10.

}11.

12.

function PrintType(item : boolean){13.

Debug.Log("I'm a boolean, type boolean");14.

}15.

16.

function PrintType(item : Array){17.

Debug.Log("I'm an array, type Array");18.

}19.

20.

function PrintType(item: GameObject){ //catches everything else21.

Debug.Log("I'm something else");22.

}23.

24.

function PrintType(){25.

Debug.Log("You forgot to supply an argument!");26.

}27.

28.

PrintType();29.

PrintType("hello");30.

PrintType(true);31.

So variables have different types, such as String and int. But what if you need a new type that does something different?

Classes are simply new types that YOU create.

Code:

class Person{1.

var name;2.

var career;3.

Newbie guide to Unity Javascript (long) http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long)

18 of 32 29.08.2013 07:52

}4.

5.

//Create objects of type Person6.

var john = Person();7.

john.name = "John Smith";8.

john.career = "doctor";9.

Debug.Log(john.name + " is a " + john.career);10.

The above class has two class variables, or properties, name and career. You access them by typing the name of the

instance (in this case, John) followed by a period and the name of the property.

You can also pass arguments when creating instances of a class. You do this by creating a constructor, which is aspecial function that is automatically called whenever a new instance of your class is created. This function has the same

name as your class, and is used to initialize the class:

Code:

class Animal{1.

var name;2.

function Animal(n : String){ //this is the constructor3.

name = n;4.

Debug.Log(name + " was born!");5.

}6.

}7.

8.

cat = Animal("Whiskers"); //var keyword is optional when creating instances!9.

Classes can have regular functions as well. Class functions are sometimes called methods. Again, you access these bytyping the name of your instance followed by a period and the function name (don't forget the parenthesis). This is useful

for having instances interact with one another:

Code:

class Person{1.

var name : String;2.

function Person(n : String){3.

name = n;4.

}5.

Newbie guide to Unity Javascript (long) http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long)

19 of 32 29.08.2013 07:52

function kiss(p : Person){6.

Debug.Log(name + " kissed " + p.name + "!");7.

}8.

}9.

10.

jenni = Person("Jenni");11.

bob = Person("Bob");12.

jenni.kiss(bob);13.

Classes can inherit or extend (add functionality to) another class. The class that gets inherited from is usually called the

base class or the parent class. The extended class is also called the child class or the derived class.

This will be our base class:

Code:

class Person{1.

var name : String;2.

function Person(n : String){ //constructor3.

name = n;4.

}5.

function Walk(){ //class function6.

Debug.Log(name + " is walking");7.

}8.

}9.

To extend this class, create a new class with the keyword 'extends':

Code:

class Woman extends Person{1.

var sex : String;2.

Newbie guide to Unity Javascript (long) http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long)

20 of 32 29.08.2013 07:52

function Woman(n : String){ //constructor3.

super(n); //calls the original constructor and sets name4.

sex = "female"; //adds additional functionality to the extended class5.

}6.

function Walk(){7.

super.Walk(); //calls the original function8.

Debug.Log("And she is so sexy!"); //adds additional functionality to the extended class9.

}10.

}11.

Note that we can access the base/parent class properties and functions by using the keyword 'super'.

If we create an instance of Woman and call function Walk(), both the parent and child function are called:

Code:

amanda = Woman("Amanda");1.

amanda.Walk();2.

Now you're probably wondering, "if classes, the types I create, can have properties and functions, why can't the built intypes"?

They do, actually.

To convert an int to a String, use the built-in function ToString():

Code:

var number = 10;1.

Newbie guide to Unity Javascript (long) http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long)

21 of 32 29.08.2013 07:52

var text = number.ToString();2.

To get the length of an Array (or a String), use the built-in property length:

Code:

var animals = Array("cat", "dog", "pig", "dolphin", "chimpanzee");1.

var total = animals.length;2.

You can use this in a for loop. Add the following two lines to the code above:

Code:

for (i=0; i<animals.length; i++){1.

Debug.Log(animals[i]);2.

}3.

This displays the contents of our array, one item at a time.

To add an item to an Array, use the function Add():

Code:

animals.Add("lemur");1.

To split a String into an array, use the function Split():

Code:

var sentence = "The quick brown fox jumped over the lazy dog";1.

var words = sentence.Split(" "[0]);2.

Debug.Log(Array(words));3.

Newbie guide to Unity Javascript (long) http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long)

22 of 32 29.08.2013 07:52

To get a part of a String, use the function Substring(). Substring takes two arguments, the starting index and the ending

index:

Code:

var sentence = "The quick brown fox jumped over the lazy dog";1.

var firstHalf = sentence.Substring(0, 19);2.

Debug.Log(firstHalf);3.

To capitalize a text string, use the function ToUpper();

Code:

var mission = "go make cool games!";1.

Debug.Log( mission.ToUpper() );2.

As you might expect, there is also a ToLower() function.

Code:

Debug.Log( ("THE END").ToLower() );1.

Intro to Scripting with Unityhttp://download.unity3d.com/support/...20Tutorial.pdf

Intro to Unity Programming on Unify Wiki

http://www.unifycommunity.com/wiki/i..._Chapter_1_Old

Unity Script Reference Page

Newbie guide to Unity Javascript (long) http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long)

23 of 32 29.08.2013 07:52

http://unity3d.com/support/documenta...riptReference/

MSDN - This is for advanced programmers. Search for JSCRIPT, as it's quite similar to Unity javascript.http://msdn.microsoft.com/en-us/library/aa187916.aspx

Reply With Quote

Posted: 05:08 PM 11-08-2009

I just wanted to say I appreciate all you have put in to this post. I was understanding everything until I got to Inheritance,where did "super(n)" come from? I see no reference or why/how it's being used in either the base class or extended

class.

Thanks

-Raiden

Location:

Posts:

Greenwood, AR

144

raiden

Quote: It doesn't matter if we win or lose, it's how we make the game!

Mobile Releases:Ultra Line Software

Tutorials:

C# Pathfinding + txt + iTweenC# 2D Snake Clone

Contact:

Larry Pendleton

Reply With Quote

Posted: 05:10 PM 11-08-2009

You are a nice person, making a long guide to programming for newbies. Thanks for being at this community. KHopcraft

Newbie guide to Unity Javascript (long) http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long)

24 of 32 29.08.2013 07:52

Location:

Posts:

Sooke

3,216

-Insert quote here

---Famous Person

Reply With Quote

Posted: 05:12 PM 11-08-2009

No problem.

"Note that we can access the base/parent class properties and functions by using the keyword 'super'."

super simply refers to the parent/base class.

Location:

Posts:

USA

1,223

tonyd

Originally Posted by Raiden

I just wanted to say I appreciate all you have put in to this post.

I was understanding everything until I got to Inheritance, where did "super(n)" come from? I see no

reference or why/how it's being used in either the base class or extended class.

Reply With Quote

Posted: 07:02 AM 11-09-2009

Thank You!tlass

Newbie guide to Unity Javascript (long) http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long)

25 of 32 29.08.2013 07:52

Location:

Posts:

Hamburg

19

Reply With Quote

Posted: 07:09 AM 11-09-2009

Nice post.

Location:

Posts:

Edinburgh, Scotland

52

ChrisMann

We don't see things as they are, we see things as we are.Anais Nin (1903 - 1977)

Reply With Quote

Posted: 07:24 AM 11-09-2009

Very usefull for beginners, thanks a lot.

Location:

Posts:

Valencia - Spain

558

GusM

Gustavo Muñoz - 2D & 3D artisthttp://www.gustavom.com

https://www.assetstore.unity3d.com/#/publisher/85

Reply With Quote

Posted: 10:30 AM 11-09-2009

I think this deserves a sticky.

Thank you very much for the time and effort you put into this.

WinningGuy

Newbie guide to Unity Javascript (long) http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long)

26 of 32 29.08.2013 07:52

Posts: 887

Reply With Quote

Posted: 07:16 AM 11-10-2009

Well, we'll see about that in time, but I have added it to the Scripting board FAQ.

Thanks for posting this Tony!

Unity tech writer

Location:

Posts:

Blackpool, United

Kingdom

8,695

andeeeee

Originally Posted by WinningGuy

I think this deserves a sticky.

I'm wired to the world... that's how I... know... everything...

Reply With Quote

Posted: 09:56 AM 11-11-2009

Wow, just what i need: a list to help me remember those tricky codes XPBTW, im typing this from school. HAHA! Ill study my way!

edplane

if (Half-Life == Mac.PowerPC) {

happiness += Mathf.infinity;

Newbie guide to Unity Javascript (long) http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long)

27 of 32 29.08.2013 07:52

Location:

Posts:

kokomo, IN

485

}

http://www.forum.wiaderko.com/images/smilies/ganja.gif

I think that's cute and funny...

Reply With Quote

Posted: 12:34 PM 11-12-2009

A very kind contribution.

Thank you Posts: 255

shader

Reply With Quote

Posted: 07:28 PM 11-20-2009

Great stuff! Very informative! If you can, please add to you array section how to access individual things stored in an

array. I don't know how to take array element1 and subtract it from array element2. For example:

array of vextor3's

array element2[2,3,4] - array element1[1,2,3]

= result of [1,1,1] (somehow).

Thanks again!Location:

Posts:

SF Bay Area, CA

100

Goody!

Goody!

Reply With Quote

Posted: 08:35 PM 11-21-2009

Posts: 17

Xen

Originally Posted by Goody!

Great stuff! Very informative! If you can, please add to you array section how to access individual things

Newbie guide to Unity Javascript (long) http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long)

28 of 32 29.08.2013 07:52

I may have misunderstood your post but if your array is an array of Vector3's then wouldn't this work ...

var result:Vector3 = array[2] - array[1]

(I'm a noob so i'm probably wrong)

stored in an array. I don't know how to take array element1 and subtract it from array element2. For

example:

array of vextor3's

array element2[2,3,4] - array element1[1,2,3]

= result of [1,1,1] (somehow).

Thanks again!

~Xen~

Reply With Quote

Posted: 08:40 PM 11-21-2009

Great post!

Given your extensive knowledge of UnityScript, do you think you could folow up this great post with a list of the

differences between normal js and Unity js. I have no idea how extensive the differences might be but I find myself fallinginto the trap of trying to use non-supported features or using features that are different in a *normal* way and crashing.

Posts: 17

Xen

~Xen~

Reply With Quote

Newbie guide to Unity Javascript (long) http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long)

29 of 32 29.08.2013 07:52

Posted: 08:51 PM 11-21-2009

http://www.unifycommunity.com/wiki/i...ith_JavaScript

Javascript in Unity is a lot more like JScript than Javascript.

--Eric

Posts: 21,548

Eric5h5

Volunteer Moderator Originally Posted by Xen

a list of the differences between normal js and Unity js.

Reply With Quote

Posted: 08:54 PM 11-21-2009

Eric5h5 - Excellent! Thanks

Posts: 17

Xen

~Xen~

Reply With Quote

newbie scripting

Hi and thanks for the intro,

I'm a 3d artist and don't know the basics, so all I do is copy paste and change numbers untill it works. But that way int'snot efficient and is buggy as hell.

If you're planning going to continue with Unity tutorials, which would be awesome so I don't have to bother programmers

all the time, could you make something about movement, cameras, rotation (world/self etc.) and simple AI?

Location:

Posts:

The Netherlands

Groningen

400

helioraanswer Posted: 02:32 AM 11-22-2009

Newbie guide to Unity Javascript (long) http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long)

30 of 32 29.08.2013 07:52

Nederlander, working on action adventure Gargoyle game.

www.heliora.com

Reply With Quote

Posted: 02:11 PM 11-22-2009

Thank you for a good head start. I have hired programmers, but always felt illiterate that I couldn't script well.

My New Year's resolution is to start learning Unity Java Script next year, so I won't be so handicapped.

Location:

Posts:

The Wasteland

542

RoyS

Reply With Quote

Posted: 07:04 AM 12-09-2009

thanks for the great starterguide. can i translate your guide into german and post it on the forum? that might be good for

the growing number of german unity users

Location:

Posts:

germany

4

steffenk

Reply With Quote

Posted: 09:10 AM 12-09-2009tonyd

Originally Posted by steffenk

Newbie guide to Unity Javascript (long) http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long)

31 of 32 29.08.2013 07:52

Feel free to translate it, just give me credit for the original document.

Location:

Posts:

USA

1,223

thanks for the great starterguide. can i translate your guide into german and post it on the forum? that

might be good for the growing number of german unity users

Reply With Quote

Page 1 of 6 2 3 ... Last

Newbie guide to Unity Javascript (long) http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long)

32 of 32 29.08.2013 07:52