- Joined
- Jul 9, 2008
- Messages
- 2,555
Alright, by now you should have read the first tutorial, located here.
I am considering you have a bit of experience with any programing language, thus this is a bit "advanced".
We'll be doing this in JavaScript, so, go to your project view and create a JavaScript file.
It really is not required to have ACTUAL JavaScript knowledge. I've learned it while working in Unity.
First of all, keep the Script Reference in mind. It's the best tool you can have in Unity.
Write the following on your script, save it and drop it on an object.
A script needs to be attached to an object to be run.
The script above should have created a notification at the bottom left of your UI, saying "Hello".
That's good, for starters.
Everything you write outside a function is run once, thus your line was run only once.
Debug is a class. Classes contain different functions, such as Log, LogError, and more. You can find them all in the Reference.
Let's take this up a notch.
The Update function is run on every frame.
Certain predefined functions are run on certain times, such as OnGUI() being run twice, in the first call, Unity builds the GUI and draws it.
Let's add some variables.
When you save this script, Unity will have a new variable for you to edit in the Inspector. Toy around with it, it will spam you with the value you put in.
var always has to be there when declaring a variable.
derp is the name of your variable.
:identifier/component is used to give the engine the type of your variable. Normally, it is not needed, but it saves the engine a lot of time from trying to figure out what it is.
=0 is not needed either, but by adding this, you can have a predefined value for your variable.
Alright, let's do real stuff now.
Instantiate clones the original object, places it at position and sets the rotation to rotation, then returns the cloned object. If a game object, component or script instance is passed, Instantiate will clone the entire game object hierarchy, with all children cloned as well.
The arguments it takes are a Transform, a Vector3(space in the axes), and a Quaternion. You should ignore the Quaternion for now.
A Transform variable is basically an object's transform. You need to assign an object to it, and the script will spam the same object over the Z axis.
That's it for now, I am willing to help people out, so drop your question via a reply!
I am considering you have a bit of experience with any programing language, thus this is a bit "advanced".
We'll be doing this in JavaScript, so, go to your project view and create a JavaScript file.
It really is not required to have ACTUAL JavaScript knowledge. I've learned it while working in Unity.
First of all, keep the Script Reference in mind. It's the best tool you can have in Unity.
Write the following on your script, save it and drop it on an object.
A script needs to be attached to an object to be run.
Code:
[URL="http://docs.unity3d.com/Documentation/ScriptReference/Debug.Log.html"]Debug.Log[/URL] ("Hello");
That's good, for starters.
Everything you write outside a function is run once, thus your line was run only once.
Debug is a class. Classes contain different functions, such as Log, LogError, and more. You can find them all in the Reference.
Let's take this up a notch.
Code:
function Update(){
[URL="http://docs.unity3d.com/Documentation/ScriptReference/Debug.Log.html"]Debug.Log[/URL] ("Hello");
}
Certain predefined functions are run on certain times, such as OnGUI() being run twice, in the first call, Unity builds the GUI and draws it.
Let's add some variables.
Code:
var derp:int=0;
function Update(){
Debug.Log(derp);
}
var always has to be there when declaring a variable.
derp is the name of your variable.
:identifier/component is used to give the engine the type of your variable. Normally, it is not needed, but it saves the engine a lot of time from trying to figure out what it is.
=0 is not needed either, but by adding this, you can have a predefined value for your variable.
Alright, let's do real stuff now.
Code:
var loc:[URL="http://docs.unity3d.com/Documentation/ScriptReference/Vector3.html"]Vector3[/URL]=Vector3(0,0,0);
var a:Transform;
function Update(){
loc=Vector3(loc.x,loc.y, loc.z+1);
//The variable above is a location on the axes. Using .x/.y/.z gives you the values inside the vector.
Instantiate (a,loc, [URL="http://docs.unity3d.com/Documentation/ScriptReference/Quaternion-identity.html?from=Object"]Quaternion.identity[/URL]);
}
The arguments it takes are a Transform, a Vector3(space in the axes), and a Quaternion. You should ignore the Quaternion for now.
A Transform variable is basically an object's transform. You need to assign an object to it, and the script will spam the same object over the Z axis.
That's it for now, I am willing to help people out, so drop your question via a reply!