Game Development Reference
In-Depth Information
Step 13. To change the color of this material, click on the white box
next to Main Color in the Inspector. Select the color you want from the
Color Popup and then close it. The large sphere view of the material in
the Inspector will change to your chosen color. To change the name
of the material, click on New Material once in the Project window.
Wait a moment and then click on it again slowly. This will place you in
editing mode for the material name. Type in a new name and hit the
Enter key.
Step 14. To add material to the cube, drag and drop your material
from the Project window onto the cube in the Scene. Alternatively,
you can drag and drop the material from the Project window and
drop it onto the cube listed in the Hierarchy window. Both will achieve
the same effect. The cube will be colored.
Step 15. In the Project window, select Create and then JavaScript.
The JavaScript created will be called NewbehaviorScript . Change this,
by slow clicking on it, as you did with the material, to spin .
Note
When you create a new JavaScript file, you only give it a name. Do not
add .js on the end. Unity will do this for you automatically. However, in
the Project, spin.js will only appear in the list as spin , without the .js on
the end.
Step 16. Double-click on it and a code/text editor will open for
entering code. In the code editor type:
function Update()
{
transform.Rotate(Vector3.up * 10);
}
The code must be EXACTLY as it appears here. Ensure that you have the
correct spelling and capitalization, as otherwise it may not work. For large
spaces, for example, before the word transform, insert a tab. When you
are done, save your code in the text editor.
Note
The code in Step 15 contains the Unity function Update() . Whatever code
you place inside Update() will be run once each main loop. Therefore, the
code in Step 15 will run over and over again for the entire time the play
button is down.
Step 17. Return to Unity and drag and drop the spin code from the
Project window onto the cube in the Hierarchy window. You'll notice
that if you select the cube, the spin script will appear as a component
added to the cube in the Inspector as shown in Figure 1.22 .
Search Nedrilad ::




Custom Search