Unity3D-Basic Scripting

Páginas: 15 (3576 palabras) Publicado: 23 de octubre de 2012
UNITY SCRIPTING
BÁSICO

In this tutorial we will be learning how to create and use scripts in Unity and how scripts are structured. This tutorial is aimed at those who are new to Unity and need a quick guide on how Unity handles scripts so that they can begin working on scripts if they already have a firm grasp of JavaScript or so that they can continue on with other tutorials and guides witha foundation of knowledge on this topic. Unity supports three types of scripting language. • • • A version JavaScript C# Boo, which is a derivative of Python

Many game engines use scripting languages, to name two big ones: Hero Engine and Unreal Engine both have integrated scripting languages (HeroScript and UnrealScript respectively). These languages are based on or are similar to JavaScript.Applications such as Flash also have integrated scripting languages (ActionScript) which is also similar to JavaScript. There are a few reasons for basing these languages around JavaScript; for example JavaScript has a relatively low level of entry, it has a solid structure, it's a well known language and it lends itself to the process of creating action centric applications. The JavaScript thatUnity uses is not pure JavaScript, its a compiled form which makes it fast and it has been extended to include lots of functions which are specific to games design.

Before We Begin
Before we begin with this tutorial we will need to create a new project, it will be useful to have a basic "level" for us to add scripting to. 1. Create a new project, including the standard asset package 2. Add a flatterrain and give it a texture 3. Add a directional light. 4. Add the first person controller from the prefabs folder of the standard assets If you are not sure how to do these things, check this guide which will create the scene we need for this tutorial. Then go to "Edit -> Render Settings" and set the Skybox Material to "Blue Sky" in the Inspector. You should end up with a scene similar to theone pictured below.

In part 1 of our Unity Scripting tutorial we created a simple scene with the default first person character controller in preparation for us to add scripts to it. Before we start scripting hit the Play button to make sure the level works correctly, you should be able to walk around on the flat plane of grass. Now in Part 2 of the tutorial we will be learning how to actuallycreate scripts for Unity. We will be learning how to do a number of trivial but very useful things in this part of the tutorial, such as: • • • • • • How to actually create a new script How to rename the script How to edit the script How to print messages to the console (useful for testing, debugging and things) How to attach a script to an object How to manipulate and object

Creating A NewScript
In the Project panel click the "Create" button and select "JavaScript" to create a new JavaScript file. If you want to work in C# or Boo then select either of those instead, but this tutorial will be focusing on using JavaScript. When you do this you will see a new file has been added to the Project panel called "NewBehaviousScript", this is a blank script. To rename the script click the nametwice and enter the new name.

To edit the script double click the script to launch the code editor. If you do this, you will see that the script has a single function in it, called "Update()", this is a special function which will be called every time the frame updates.

Our First Script
For our first script we will create a script which will cause a cube to rotate. This exercise will teach youhow to create a script, attach it to an object and how to manipulate the object it is attached to. 1. Create a new script and call it "RotateCube". 2. Double click it to open the script editor. 3. Delete the Update function from the script. Now enter the following code then save the script: function Update() {   transform.Rotate(0, 5*Time.deltaTime, 0); } Now in order for this script to...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Scripting
  • Cross site scripting
  • Lenguajes de scripting en servidores web:
  • basico
  • basico
  • mIRC Scripting
  • basica
  • basico

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS