Senin, 20 Februari 2017

Empty Script

Just like in Scratch, in Unity we can create script for a Sprite that will contain the program code that will be performed by the Sprite. When we create the script for the first time, the computer will automatically fill in the following few lines of code (in C# language).




In Scratch, the above basic code has the same meaning as the following script.



In the above Scratch program, the Start block is executed when the cat Sprite is created for the first time which is at the start of the program, while the Update block is repeatedly executed forever.

The term block in Scratch is called function or method in Unity C# language.  In Unity, the Start method is executed only once at the time the cat Sprite is created which is at the beginning of the program while the Update method is executed repeatedly forever as long as the Sprite still exists.

In the Start and Update method we see the { and } symbols. The { symbol marks the begin of a function and the } symbol marks the end of a function. In Scratch these Symbol don't exist. Thus, all lines of code which exist between { and } symbols in Start function will be executed at the start of a program. Also, all lines of code between { and } symbols in Update method will be repeatedly executed forever.

Below is a You Tube video on how to create an Empty Script in Unity for a Sprite.






Tidak ada komentar:

Posting Komentar