Whats the best way to learn Unity Script? Should I learn Website javascript then Unity script or something else? Every tutorial I have found is only good if You know javascript already.
don’t waste time on learning website javascripting
just toy with the whole set of example projects that exist and work through the tutorials that will be more than enough as there is no magic or special thing to learn about unity javascript. there are no special functionalities or alike that you need to learn in a complex way, just the general codeflow stuff (if,while,for,repeat)
if you want a language with a lots of resources to learn, learn C# instead ![]()
I have been looking through all the tutorials but I don’t code really. I just don’t understand it. I am more of a modeler. I just want to understand Javascript and come up with some basic scripts. One script I want to make is a simple one that has a timer. When the timer reaches zero the player fails and shows a GUI. Unless they reach a trigger game object… they win and it shows a GUI. Maybe even unlock another level. This is a simple maze game I am just messing around with to better understand scripting. thanks
What you talk about there has not much to do with learning the language.
Thats learning how to develop game mechanics and thats step 2, after you learned the language and basic programming (and the required logical thinking to develop code at all)
Once you learned that, this step 2 is rather easy. All you have to do is
- write out what you want, in a structured way
- Seperate it in steps
- think about what they mean in code.
for example:
The player must reach point X to gain Y
Step 1: Player reaches Point X
Step 2: Give player Y
-
Requirement: We must have a way to decide when the player reaches point X
Solution: use a trigger object and attach a script that has OnTriggerEnter
So far so good, but that only covers the “when something reaches point x”. The missing thing is “if the player”, which we check through exactly that, an IF statement that checks if it is the player
-
Requirement: Our script must know what to give
Solution: Have a public variable to which you can assign the prefab of what you want to give if it is an object and “give it to him” the way you intend to (instantiate and attach, …) or have code that grants the points, live or whatever.
and I doubt you read through all, especially the 2d jump’n’run tutorial or all the tutorials at unitytutorials etc
Thanks for your help. I did the 2d side scroller tutorial and the 3d platformer tutorial. Also the scripting tutorial.
Check out the tornadoTwins tutorials on youtube… They are covering almost all the basics of unity.
?
I don’t get it.
You are a member since Feb 2010, you have 300 posts +. If you are asking where you can learn Unityscript, I must assume you know C#.
But if it is the case, why would you learn Unityscript, since you know C# already ?
FYI, it looks like they’ve officially started calling the language “UnityScript” in 3.0, according to beta release notes. It’s gotten far enough away from JavaScript that treating it like JavaScript is going to make for even less optimized code than before.
Hi. Yes, Like I said I am more of a modeler. I am not that new to Unity to where I need the Tornado Twins lol. I have been using Unity for about a year now. I know some of the basics of Javascript though. Meaning the layout of it. I can “repair” basic scripts, like if they don’t have capital letters or something like that. I just can’t make my own scripts from scratch. And I also knew that it was called Unity Script. I like that name
Thanks. Also I took a look at that popular book on amazon about Unity Script.
var endTrigger : Collider; //'var' says that we want to store a reference to something -- in this case a collider. 'endTrigger' is the name of the variable, and can be changed to whatever you want. ': Collider' says the 'endTrigger is a collider instance. If you change it to something else, such as 'Rigidbody' or 'Transform', the script will not work.
var startTime : float = 10.0; //how much time the player can have before he/she fails. A float is a floating point number -- basically a decimal(as opposed to int, an integer, which is basically a whole number). Once again, 'startTime' is just the variable name and can be changed.
private var timeLeft : float = 0.0; //this will store how much time the player has left. Once again, 'timeLeft' is just the variable name.
//'function' says that this is a block of code that we want to execute. 'Start' is the name of the function. 'Start' is part of UnityScript, and is called automatically when the game runs.
function Start(){
timeLeft = startTime; //set how much time we have left
}
//Update is another unityscript function that is called automatically every frame.
function Update(){
timeLeft -= Time.deltaTime; //Time.deltaTime is the number of seconds it took to complete the last frame. So if you subtract Time.deltaTime from timeLeft each frame, timeLeft will be decremented by ~1.0, thus giving us a timer.
//in this code, 'Time' is a UnityScript class(look it up in the docs), and deltaTime is a variable of that class (such as our variables, startTime, and timeLeft). Note that if you changed the name of the timeLeft variable when you defined it(var timeLeft), you'll need to change it here too.
}
//OnTriggerEnter is called automatically when we collide with a collider that is set to be a trigger. Note that this function has a variable that is passed in: 'col'. It is an instance of a Collider, and it is automatically set to the collider we collided with.
function OnTriggerEnter(col : Collider){
//if the collider we collided with is endTrigger, and we're not out of time, call the 'Log()' function of the 'Debug' class.
if(col == endTrigger timeLeft > 0.0) Debug.Log("Win.")
//note that '==' is used for comparison, not assignment. Also the ''.
}
(Note that this was typed in a browser – it should execute, but I may have missed something)
It’s a simple script, but it demonstrates a lot of syntactical and logical concepts. If you can understand this, the chances are you know enough to (at least learn how to) make a game.
Best wishes,
-Lincoln Green
Thanks so much. I think I understand it I will put it in the game and see what happens. ![]()