Pix-Labs, I have a question in regards to your splash screen tutorial. I know it has been almost a year since you posted it, but my question is, what would the difference be in declaring and calling the variables in JavaScript versus what you have written in the tutorial. I am trying to use your tutorial as a basis for one of my projects for class, but I can't seem to find a splash screen tutorial out there that uses JS. Any help will be appreciated, thank you very much. -Steven

Hey Steven,

Thanks for taking the time to get in touch, so sorry for only getting back to you now.

Declaring variables in JavaScript is a bit different as C# follows a strict OOP style, where JavaScript is a bit of a hybrid, however it is widely considered an event driven scripting language.

Unity uses JavaScript a little differently, and if you have a look at some Unity docs, you will most likely see them refer to it a Unity Script, as it more of an adaptation of JavaScript.

That being said (my 5 cents haha) it is still JavaScript, and that is what it will remain in its simplest form.

So let’s get into it. Here is an example of a C# variable:

public int level;

Now, in order to declare this same variable in Unity Script (JavaScript) you would do this:

public var level : int;

As you can see we keep the important ‘public’ reference as this alllows variables to be changed in the Unity editor.

Once this is done we start of with ‘var’ which shows we are creating a variable and not a function.

We then name our variable, and should we feel the need to we declare the type by appending a ‘:’ (colon) and then the type (int) followed by a semi color (;).





For the most part, it is not that complicated to rewrite a script to JavaScript (Unity Script). To help you out, I have added the JavaScript version here for you.





———————————-

#pragma strict

public var level:int;

public var setTime:float;

public var dimTime:float;

public var zoomSpeed:float;

public var dimLight:Light;

var c:Camera;

var timer:float;

function Start () {

c = GetComponent(Camera);

timer = 0.0f;

}

function Update () {

timer += Time.deltaTime; //Adds Time.deltaTime to timer each update

c.fieldOfView -= zoomSpeed; //Zooms in Camera

if (timer > dimTime && timer < setTime) {

dimLight.intensity -= zoomSpeed; //Dims Lights

} else if (timer > setTime) {

Application.LoadLevel (level); //Loads Level at index

}

}

———————————-

(Note: This code may not be perfect :) )

I hope that helps, and should you require any further help, just shout! : )





If you ever need any quicker responses just comment on a video on my YouTube account or grab my Skype ID





Always happy to help,

Dylan (PixLab Games)