Unity 3: Building a Rocket Launcher

Exclusive offer: get 50% off this eBook here
Unity 3 Game Development Hotshot

Unity 3 Game Development Hotshot — Save 50%

Eight projects specifically designed to exploit Unity's full potential

$29.99    $15.00
by Jate Wittayabundit | September 2011 | Web Graphics & Video

Only Unity fits the bill of being a game engine that allows you to create a full 3D game for free, and with phenomenal community support.

In this article by Jate Wittayabundit, author of Unity 3 Game Development Hotshot, we will learn how to create a rocket launcher. Here, we will first use the FPS camera and controller from the Unity built-in FPS package, but we will tweak our camera view to see from the character's shoulder as in Resident Evil 4 or 5. Then, we will adapt the built-in FPS controller script to be able to play the animation of the character, and make the controller similar to the Resident Evil style controller. Next, we will create a rocket prefab and the rocket launcher script to fire our rocket, which will also include the use of the built-in fire explosion particle and custom smoke particle effect from the launcher when we fire.

 

(For more resources on this subject, see here.)

Mission briefing

We will create a character that carries a rocket launcher and is able to shoot it as well as creating the camera view looking back from the character shoulder (third-person camera view). Then, we will add the character controller script to control our character, and the player will have to hold the Aim button to be able to shoot the rocket, similar to the Resident Evil 4 or 5 styles.

What does it do?

We will start with applying the built-in CharacterMotor, FPSInputController, and MouseLook scripts from the built-in FPS character controller. Then, we will add the character model and start creating a new script by adapting part of the code in the FPSInputController script. Then, we will be able to control the animation for our character to shoot, walk, run, and remain idle.

Next, we will create a rocket prefab and the rocket launcher script to fire our rocket. We will use and adapt the built-in explosion and fire trial particle in Unity, and attach them to our rocket prefab. We will also create a new smoke particle, which will appear from the barrel of the rocket launcher when the player clicks Shoot.

Then, we will create the scope target for aiming. We will also create the launcher and smoke GameObject, which are the start position of the rocket and the smoke particle.

Finally, we will add the rocket GUITexture object and script to track the number of bullets we have let, at player each shot. We will also add the Reload but on to refill our bullet when the character is out of the bullet.

Why Is It Awesome?

When we complete this article, we will be able to create the third-person shooter style camera view and controller, which is very popular in many games today. We will also be able to create a rocket launcher weapon and particle by using the prefab technique. Finally, we will be able to create an outline text with the GUITexture object for tracking the number of bullets left.

Your Hotshot Objectives

In this article, we will use a third-person controller script to control our character and combine it with the built-in first-person controller prefab style to create our third-person shooter script to fire a rocket from the rocket launcher. Here is what we will do:

  • Setting up the character with the first-person controller prefab
  • Creating the New3PSController and MouseLook_JS scripts
  • Create a rocket launcher and a scope target
  • Create the rockets and particles
  • Create the rocket bullet UI

Mission Checklist

First, we need the chapter 5 project package, which will include the character model with a gun from the Unity FPS tutorial website, and all the necessary assets for this article.

So, let's browse to http://www.packtpub.com/support?nid=8267 and download Chapter5.zip package. Unzip it and we will see Chapter5.unitypackage, and we are ready.

Setting up the character with the first-person controller prefab

In the first section of this article, we will make all the necessary settings before we create our character on the scene. We will set up the imported assets and make sure that all the assets are imported in the proper way and are ready to use by using the Import Package in the Project view inside Unity. Then, we will set the light, level, camera, and put our character in the scene with the first-person controller prefab.

We will import the Chapter5.unitypackage package to Unity, which contains the Chapter5 folder. Inside this folder, we will see five subfolders, which are Fonts, Level, Robot Artwork, Rocket, and UI. The Fonts folder will contain the Font file, which will be used by the GUI. The Level folder will contain the simple level prefab, its textures, and materials. Robot Artwork is the folder that includes the character FBX model, materials, and textures, which can be taken from the Unity FPS tutorial. The Rocket folder contains the rocket and rocket launcher FBX models, materials, and textures, which can be taken from the Unity FPS tutorial. Finally, the UI folder includes all the images, which we will use to create the GUI.

Prepare for Lift Off

In this section, we will begin by importing the chapter 5 Unity package, checking all the assets, setting up the level, and adding the character to the scene with the FPS controller script.

First, let's create a new project and name it RocketLauncher, and this time we will include the built-in Character Controller package and Particles package by checking the Character Controller.unityPackage and Particles.unityPackage checkboxes in the Project Wizard. Then, we will click on the Create Project but on, as shown in the following screenshot:

Unity 3: Building a Rocket Launcher

Next, import the assets package by going to Assets | Import Package | Custom Package.... Choose Chapter5.unityPackage, which we just downloaded, and then click on the Import but on in the pop-up window link, as shown in the following screenshot:

Unity 3: Building a Rocket Launcher

Wait until it's done, and you will see the Chapter5 folder in the Window view. Make sure that we have all have folders, which are Fonts, Level, Robot Artwork, Rocket, and UI, inside this folder. Now, let's create something.

Engage Thrusters

In this section, we will set up the scene, camera view, and place our character in the scene:

  1. First, let's begin with creating the directional light by going to GameObject | Create Other | Directional Light, and go to its Inspector view to set the rotation X to 30 and the position (X: 0, Y: 0, Z: 0).
  2. Then, add the level to our scene by clicking on the Chapter5 folder in the Project view. In the Level folder, you will see the Level Prefab; drag it to the Hierarchy view and you will see the level in our scene.

    Unity 3: Building a Rocket Launcher

  3. Next, remove the Main Camera from the Hierarchy view because we will use the camera from the built-in First Person Controller prefab. So, right-click on the Main Camera on the Hierarchy view and choose Delete to remove it.
  4. Then, add the built-in First Person Controller prefab to the Hierarchy view by going to the Standard Assets folder. Under the Character Controllers folder, you will see the First Person Controller prefab; drag it to the Hierarchy view.

    Unity 3: Building a Rocket Launcher

  5. In the Hierarchy view, click on the arrow in the front of the First Person Controller object to see its hierarchy, similar to the one shown in the following screenshot:

    Unity 3: Building a Rocket Launcher

  6. Then, we go back to the Project view. In the Chapter5 folder inside Robot Artwork, drag the robot.fbx object (as shown in the following screenshot) on top of the Main Camera inside the First Person Controller object in the Hierarchy.

    Unity 3: Building a Rocket Launcher

  7. This will cause the editor to show the window that tells us this action will break the prefab, so we just click on the Continue but on to break it. It means that this game object will not be linked to the original prefab.
  8. Next, remove the Graphics object above the Main Camera. Right-click on it and choose Delete. Now we will see something similar to the following screenshot:

    Unity 3: Building a Rocket Launcher

    We have put the robot object as a child of the camera because we want our character to rotate with the camera. This will make our character always appear in front of the camera view, which is similar to the third-person view. This setup is different from the original FPS prefab because in the first person view, we will not see the character in the camera view, so there is no point in calculating the rotation of the character

  9. Now, click on the First Person Controller object in the Hierarchy view to bring up the Inspector view, and set up the Transform Position of X: 0, Y: 1.16, Z: 0|. Then, go to the Character Controller, and set all values as follows:
    • Character Controller (Script)
    • Height: 2.25
    • Center
      • X: -0.8, Y: 0.75, Z: 1.4
  10. Move down one step by clicking on Main Camera in the Hierarchy view and go to its Inspector view to set the value of Transform and Mouse Look as follows:
    • Transform
    • Position
      • X: 0, Y: 1.6, Z: 0
    • Mouse Look (Script)
    • Sensitivity Y: 5
    • Minimum Y: -15

    We will leave all the other parameters as default and use the default values.

    Unity 3: Building a Rocket Launcher

    Then, we will go down one more step to set the Transform of the robot by clicking on it to bring up its Inspector view, and set the following:

    Now, we are done with this step. In the next step, we will adjust and add some code to control the animation and movement of our character the FPSInputController script.

    1. If the user presses it, we want the character to stop moving and play the shooting animation to prepare the character to be able to fire. We also set the maximum and minimum of the camera rotation on the Y-axis, which limits the camera to rotate up and down only. Then, we set the motor.inputMoveDirection to Vector3. zero because we don't want our character to move while he/she is executing the shooting action.
    2. On the other hand, if the user doesn't press E, we check for the user input. If the user presses the right arrow or let arrow, we change the speed to run speed; if not we set it to walk speed. Then, we applied the movement speed to motor. movement.maxForwardSpeed, motor.movement.maxSidewaysSpeed, and motor.movement.maxBackwardsSpeed.
Unity 3 Game Development Hotshot Eight projects specifically designed to exploit Unity's full potential
Published: August 2011
eBook Price: $29.99
Book Price: $49.99
See more
Select your format and quantity:

 

(For more resources on this subject, see here.)

Objective Complete - Mini Debriefing

Basically, what we have done here is preparing the scene ready for the next step. In this step, we added the directional light, level prefab, and the built-in First Person Controller prefab to the scene. We also adjusted the built-in First Person Controller prefab by removing the Graphics object from the prefab object and adding the robot prefab as a child of the Main Camera of the First Person Controller prefab object for the new graphics, which we will see from the Main Camera, as shown in the following screenshot:

Unity 3: Building a Rocket Launcher

However, we will see the character's arm block half of the screen, which is because we don't have the script to control the animation, yet. We will do that in the next step.

Classified Intel

At the beginning of this article, we imported the Chapter5.unityPackage file, but what about exporting?

A good way to share assets between projects is by exporting them as unitypackage. A unitypackage also saves the import settings of the assets. To make it easier to include all needed assets, the export dialog automatically checks for dependencies. To export assets as unitypackage just select the items, right-click, and choose Export Package.

For example, if we copy the png file from another project to the Unity Assets folder or import in the Project view, the default Texture Importer Texture Type| in Unity will always set to Texture. On the other hand, if we export this file by using unityPackage, we will be able to set the Texture Type to GUI or Normal map. Then, when we import this unityPackage to other projects, we will get the same settings we can see in the following screenshot:

Unity 3: Building a Rocket Launcher

We can easily create the unityPackage file by just right-clicking on the file or folder in the Project view that we want to export and choosing Export Package... to bring up the Exporting package window as we can see in the following screenshot (we have selected the Chapter 5 folder for the example):

Unity 3: Building a Rocket Launcher

In this window, we can choose what we want to export by enabling the checkbox. Then, we can click on the Export Package... but on and choose the path that we want to export.

When the file is chosen in the Project window and we choose Export Package..., Unity will collect all the dependencies for that file and show them in the Exporting package window . So, selecting a scene file and exporting that will automatically export all the assets used in that scene. If an asset is only loaded from code and is not used directly in the scene or referenced from a public member variable, Unity will not know that it needs to be included. More information on the topic can be found at: http://unity3d.com/support/documentation/Manual/HOWTO-exportpackage.html.

Creating the New3PSController and MouseLook_JS scripts

In the last section, we imported the Chapter5 Unity package and created our scene, which included all the basic setup. In this step, we will create a New3PSController script by using the old built-in FPSInputController script , and add some script to control the animation or the character to run, walk, aim, or shoot. We will also create the MouseLook_JS script , which is the JavaScript version of the MouseLook built-in script that is writ en in C#. The MouseLook_JS script is used to control the rotation of the camera in our scene.

Prepare for Lift Off

We are first going to create the New3PSController script

We will start by creating a new MouseLook_JS by going to Assets | Create | Javascript and name it MouseLook_JS, then double-click to open it in MonoDevelop and replace the script as follows:

@script AddComponentMenu("Camera-Control/Mouse Look JS")

enum RotationAxes { MouseXAndY, MouseX, MouseY }
public var axes : RotationAxes = RotationAxes.MouseXAndY;
public var sensitivityX : float = 15;
public var sensitivityY : float = 15;

public var minimumX : float = -360;
public var maximumX : float = 360;

public var minimumY : float = -60;
public var maximumY : float = 60;

private var rotationY : float = 0;

public function Start () : void {
// Make the rigid body not change rotation
if (rigidbody)
rigidbody.freezeRotation = true;
}

public function Update () : void {
if (axes == RotationAxes.MouseXAndY)
{
var rotationX : float = transform.localEulerAngles.y + Input.
GetAxis("Mouse X") * sensitivityX;

rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);

transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
}
else if (axes == RotationAxes.MouseX)
{
transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
}
else
{
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);

transform.localEulerAngles = new Vector3(-rotationY, transform.
localEulerAngles.y, 0);
}
}

This script is the JavaScript version of the MouseLook built-in script . This way we can edit and adapt the script without bothering anything in the built in script. Even though, in Unity we can use both C# and JavaScript languages in the same project (we will talk about this in more detail in Chapter 8, Let the World See your Carnage! Saving, Loading, and Posting your High Score), it's bet er to pick one language for the entire project because it will be very difficult to access the parameters between different languages.

Then, we will go back to Unity and create a new script named New3PSController by going to Assets Create | Javascript|. Then, we will right-click it and choose Sync MonoDevelop Project (if you set MonoDevelop as the main editor) or just double-click it to open the scrip It will open the new script in MonoDevelop (or your default editor Unitron/UniScite).

In MonoDevelop, at the top let in the Solution view, you will see the name of our project; click on the arrow in front of it. In the Assets folder, go to Assets | Standard Assets | Character Controllers | Sources | Scripts. Double-click the FPSInputController file to open it.

Unity 3: Building a Rocket Launcher

Next, we go to the FPSInputController file , copy the code in it to the New3PSController file that we just created. Then, we close the FPSInputController file , and go to the New3PSController file at the end of this script. We will see the following line of code:

@script AddComponentMenu ("Character/FPS Input Controller")

Change the preceding line of the script to the following one:

@script AddComponentMenu ("Character/New 3PS Controller")

We are changing the name of this script because we don't want to replace the built-in script with the new one. This script will be added to the Component menu, which we will see in the Unity Editor Component Character | New 3PS Controller|.

Engage Thrusters

Now we are ready to create our script. We will start by creating the new parameters that will be used to control our character:

  1. Go to New3PSController.js, and set up the new parameters. Go to the first line of this script and type the following highlighted code:

    //Character movement speed
    public var runSpeed : int = 6;
    public var walkSpeed : int = 2;
    private var int_moveSpeed : int;
    //Animation Params
    public var _animation : Animation;
    public var idleAnimation : AnimationClip;
    public var walkAnimation : AnimationClip;
    public var runAnimation : AnimationClip;
    public var shotAnimation : AnimationClip;
    public var walkAnimationSpeed : float = 1.5;
    public var idleAnimationSpeed : float = 1.0;
    public var runAnimationSpeed : float = 2.0;
    public var shotAnimationSpeed : float = 0.5;
    //Camera Rotation Limit
    public var minRotateY : float = -15;
    public var maxRotateY : float = 60;

    //Mouse Look
    private var mouseLook : MouseLook_JS;

    //Character Motor
    private var motor : CharacterMotor;

    Here, we just set up the necessary parameters for controlling the animation of our character and set the Y-axis camera limit rotation.

  2. Next, we will add some code in the Awake() function. Go to the function and add the following highlighted code:

    // Use this for initialization
    public function Awake () : void {
    motor = GetComponent(CharacterMotor);
    //Hide cursor
    Screen.showCursor = false;
    //Setup the character move speed to walk speed
    int_moveSpeed = walkSpeed;

    //Get MouseLook component
    mouseLook = Camera.main.GetComponent(MouseLook_JS);

    //Setup Animation
    _animation[walkAnimation.name].speed = walkAnimationSpeed;
    _animation[walkAnimation.name].wrapMode = WrapMode.Loop;
    _animation[runAnimation.name].speed = runAnimationSpeed;
    _animation[runAnimation.name].wrapMode = WrapMode.Loop;
    _animation[idleAnimation.name].speed = idleAnimationSpeed;
    _animation[idleAnimation.name].wrapMode = WrapMode.Loop;
    }

    Here, we just add the code to hide the mouse cursor, set the character movement speed value equal to the walk speed, get the mouse look component, and set up th animation speed and warp mode.

  3. Go to the Update() function and add the highlighted code after the if (directionVector != Vector3.zero) {} statement:

    // Update is called once per frame
    public function Update () : void {
    // Get the input vector from kayboard or analog stick
    var directionVector = new Vector3(Input.GetAxis
    ("Horizontal"), 0, Input.GetAxis("Vertical"));

    if (directionVector != Vector3.zero) {
    ...............
    }

    if (Input.GetKey(KeyCode.E)) {
    //Set the maximum and minimum limit rotation on Y-axis
    for the main camera
    mouseLook.minimumY = minRotateY;
    mouseLook.maximumY = maxRotateY;
    //No Movement Direction
    motor.inputMoveDirection = Vector3.zero;
    } else {
    //No Y-axis Rotation
    mouseLook.minimumY = 0;
    mouseLook.maximumY = 0;
    //Change the movement speed of the character
    if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.
    RightShift)){
    int_moveSpeed = runSpeed;
    } else {
    int_moveSpeed = walkSpeed;
    }
    motor.movement.maxForwardSpeed = int_moveSpeed;
    motor.movement.maxSidewaysSpeed = int_moveSpeed;
    motor.movement.maxBackwardsSpeed = int_moveSpeed;
    ////////////////////////////////////////////////////////
    //Checking if the character is moving or not
    if (directionVector != Vector3.zero) {
    if (int_moveSpeed == walkSpeed) {
    _animation.CrossFade(walkAnimation.name);
    } else {
    _animation.CrossFade(runAnimation.name);
    }
    } else {
    _animation.CrossFade(idleAnimation.name);
    }
    // Apply the direction to the CharacterMotor
    motor.inputMoveDirection = transform.rotation * directionVector;
    motor.inputJump = Input.GetButton("Jump");
    }
    }

    In the preceding function, we have used Input.GetKey(KeyCode.E) for aiming and Input.GetKey(KeyCode.LeftShift) || Input. GetKey(KeyCode.RightShift) for running, which will get the input as the E key and right arrow/let arrow keys on the keyboard. However, this isn't flexible if we want to change the input or if we want to put this game on another platform that doesn't have a keyboard. We can solve this by setting the custom Input but on via the Input Manager and using Input.GetButton() instead of Input.GetKey(), which is much more dynamic for adjusting the input controller for different platforms. We can go to the Input Manager (Edit Project Settings | Input)|.

  4. Go back to Unity, click on the First Person Controller object in the Hierarchy view, go to its Inspector view, and right-click the FPSInput Controller (Script) and choose Remove Component to remove it. Then, we will go to the Project view and drag the New3PSController script that we just created to the First Person Controller object in the Hierarchy view.
  5. Go to the Inspector view of First Person Controller object in the New3PSController component and set the following:
    • Animation: robot (robot game object in the Hierarchy view)
    • Idle Animation: idle (Chapter5/Robot Artwork/robot@idle/idle)
    • Walk Animation: walk (Chapter5/Robot Artwork/robot@walk/walk)
    • Run Animation: run (Chapter5/Robot Artwork/robot@run/run)
    • Shoot Animation: shoot (Chapter5/Robot Artwork/robot@idle/ shoot)

    The Idle, Walk, Run, and Shoot Animation will be located in the Project view inside robot@idle, robot@walk, robot@run, and robot@shoot objects, as shown in the following screenshot:

    Unity 3: Building a Rocket Launcher

  6. Before we finish the section, we will add our MouseLook_JS script to the First Person Controller instead of the old MouseLook. So, click on the First Person Controller object in the Hierarchy view, go to its Inspector view. In the Mouse Look (Script) component, we will click on the circle icon at the right of Script and choose

    Unity 3: Building a Rocket Launcher

  7. Then, go down one step and click on the Main Camera object in the Hierarchy view; go to its Inspector view. In the Mouse Look (Script) component, click on the circle icon at the right of Script and choose MouseLook_JS as we did earlier.

    Now, click Play to see the result. You will be able to control your character's moves; run by holding the Shift key and jump by pressing the space bar. However, pressing the E key will stop our character's movements because we didn't set up the aiming and shoot animation in our script yet. We will do this in the next section.

Objective Complete - Mini Debriefing

We just created our New3PSController.js script by using the old built-in FPSInputController.js script as the base script. We also added the new code section to control the animation of the character while it is moving, running, or idle. Then, we limited the movement and rotation of the camera by applying the character movement direction to Character Motor and the Main Camera.

Then, in the Update() function , we added the new section of the code to control the animation of our character. At first, we check whether or not the user has pressed E:

Next, we checked the character movement direction to play the run animation, walk animation, or idle animation (we can also have the jump animation in here, but in this example we don't have the jump animation, so we just leave it).

At last, we applied the movement direction and jump to the character motor for the user to be able to control the movement of this character, and we are done with this step. In the next step, we will add the shoot animation and function, fire script, rocket launcher, and scope target to our character.

Classified Intel

In this step, we have access to the Character Motor and can change MouseLook script to MouseLook_JS script . If we take a look at the Character Motor script, we will see that it has a lot of parameters to adjust. In our case, we only pass the inputMoveDirection, inputJump, movement.maxForwardSpeed, movement.maxSidewaysSpeed, and movement.maxBackwardsSpeed parameters. We don't need to go to every parameter in the Character Motor, but there is something that we will need to know to be able to use it with our script. The Character Motor will help us to calculate the smooth movement speed including moving forward, backward, and sideways. It will calculate the gravity when the character is jumping and falling as well as check for the moving platform.

Next, we will take a look at the MouseLook script . If we open up this script, we will see that it is writ en in C#, but we need not worry as Unity allows us to access the parameters even though we are using JavaScript. As we know, we can use C# (and also Boo) scripting language to write the script in Unity similar to JavaScript. So, let's open the MouseLook and look inside—it's very similar to what we did for MouseLook_JS in JavaScript. However, there are numerous differences between writing JavaScript and C#, but we will talk about the basics of syntax.

Both of the preceding scripts do the same thing, but use different syntaxes. For example, if we want to create a float variable in JavaScript, we can use the following line of code:

public var myNumber : float = 0;

To create a function we can use the following line of code:

public function Myfuncion () : void { //dosomething }

On the other hand, if we are using C#, we can write the following line of code:

public float myNumber = 0F;

We put the F here to tell the complier that it is a float value.

And for the function, we will use the following line of code:

public void Myfuncion () { //dosomething }

There is also some difference in syntax between both the languages. For more information, we can go to the following websites:

http://unity3d.com/support/documentation/ScriptReference/index. Writing_Scripts_in_Csharp.html
http://answers.unity3d.com/questions/12911/what-are-the-syntax- differences-in-c-and-javascrip.html.

We can also see the syntax for each language in the Unity scripting document, as shown in the following screenshot:

Unity 3: Building a Rocket Launcher

You can also buy the JavaScript to C# converter package or C# to Javascript converter package there.

Creating the rocket launcher and scope target

From the last section, we have the setup for the Aiming but on to stop our character's movement as well as control the animation of our character by using crossFade() . In this section, we will add the aiming animation, shot animation, scope target UI, rocket launcher script, and rocket launcher object.

Engage Thrusters

We will start with creating a rocket launcher and adding the New3PSController script to it. Then, our character will be able to shoot the rocket:

  1. Go to Unity editor, GameObject | Create Empty , and name the object RocketLauncher, and then we drag this object inside the Main Camera object in the Hierarchy view as shown in the following screenshot:

    Unity 3: Building a Rocket Launcher

  2. Then, go to the Inspector view of the RocketLauncher to set up the Transform | Position, X: 0, Y: 0, Z: 2. Next, we create the GUITexture for the scope target by going to GameObject | Create Other | GUI Texture and naming it ScopeUI. Go to its Inspector and set the following:
    • GUITexture
      • Texture: scopeTarget.png (Chapter5/UI folder/ scopeTarget)
    • Pixel Inset
      • X: -16, Y: -16, Width: 32, Height: 32
  3. Create a new RocketLauncher script by going to Assets | Create | Javascript and name it RocketLauncher, double-click on it to open MonoDevelop . Then, go to the script and replace the code as follows:

    public var speed : float = 10;
    public var ammoCount : int = 20;

    private var lastShot : float = 0.0;

    public function Fire(_reloadTime : float) : void {
    if (Time.time > (_reloadTime + lastShot) && ammoCount > 0) {

    //Get the last shot time
    lastShot = Time.time;
    //Decrease the bullet
    ammoCount--;
    }
    }

    public function Reload () : void {
    ammoCount = 20;
    }

    • Here, we create the Fire and Reload() function s to trigger when the user presses R to reload the bullet or presses E to aim, which will be called from New3PSController.
  4. Go back to Unity and go to the Project view and drag your RocketLauncher script to the RocketLauncher object in the Hierarchy view
  5. Go to the New3PSController script to add the highlighted code between the maxRotateY and mouseLook parameters (before the Awake() function ), as shown next:


    //Camera Rotation Limit
    public var minRotateY : float = -15;
    public var maxRotateY : float = 60;

    //Scope UI
    public var scopeUI : GUITexture;
    //Rocket Launcher
    public var rocketLauncher : RocketLauncher;
    //Shot Params
    private var b_isPrepare : boolean = false;
    private var b_isShot : boolean = false;

    //Mouse Look
    private var mouseLook : MouseLook_JS;
    //Character Motor
    private var motor : CharacterMotor;
    if (directionVector != Vector3.zero) {

    }

    //Reload the rocket bullet

    if (Input.GetKey(KeyCode.R)) {
    BroadcastMessage("Reload");
    }

    if (Input.GetKey(KeyCode.E)) {
    //Show the Scope UI
    scopeUI.enabled = true;
    //Set the maximum and minimum limit rotation on Y-axis
    for the main camera
    //Set the maximum and minimum limit rotation on Y-axis
    for the main camera
    mouseLook.minimumY = minRotateY;
    mouseLook.maximumY = maxRotateY;

    //Checking if the character is playing the shot animation
    if (!b_isPrepare) {
    b_isShot = false;
    //Play the shot preparing animation function
    WaitForPrepare();
    } else {
    //If the player click fire play the shot animation again
    if ((Input.GetButton("Fire1")) && (!b_isShot)) {
    b_isShot = true;
    //Play the shot animation function
    WaitForShot();
    }
    }
    //No Movement Direction
    motor.inputMoveDirection = Vector3.zero;
    }

  6. Then, go to the Update() function and add the code before and inside if (Input.GetKey(KeyCode.E)) { (after if (directionVector != Vector3. zero) { statement) as highlighted:

    if (directionVector != Vector3.zero) {

    }

    //Reload the rocket bullet

    if (Input.GetKey(KeyCode.R)) {
    BroadcastMessage("Reload");
    }

    if (Input.GetKey(KeyCode.E)) {
    //Show the Scope UI
    scopeUI.enabled = true;
    //Set the maximum and minimum limit rotation on Y-axis
    for the main camera
    //Set the maximum and minimum limit rotation on Y-axis
    for the main camera
    mouseLook.minimumY = minRotateY;
    mouseLook.maximumY = maxRotateY;

    //Checking if the character is playing the shot animation
    if (!b_isPrepare) {
    b_isShot = false;
    //Play the shot preparing animation function
    WaitForPrepare();
    } else {
    //If the player click fire play the shot animation again
    if ((Input.GetButton("Fire1")) && (!b_isShot)) {
    b_isShot = true;
    //Play the shot animation function
    WaitForShot();
    }
    }
    //No Movement Direction
    motor.inputMoveDirection = Vector3.zero;
    }

  7. Go to the else section and add the highlighted code at the first line before if (Camera.main.GetComponent(MouseLook)) {, as follows:

    else {
    //Hide the Scope UI
    scopeUI.enabled = false;
    //Set the prepare animation to false
    b_isPrepare = false;

    //No Y-axis Rotation
    mouseLook.minimumY = 0;
    mouseLook.maximumY = 0;

    //Change the movement speed of the character
    if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey
    (KeyCode.RightShift)) {

  8. We are now done with the adding part for the Update() function . We will need to add other two functions for the WaitForPrepare() and WaitForShot() functions. So, let's go to the Update() function before @script RequireComponent (CharacterMotor) line and add the following two functions:

    private function WaitForShot () : IEnumerator {
    _animation[shotAnimation.name].speed = shotAnimationSpeed;
    _animation[shotAnimation.name].wrapMode = WrapMode.
    ClampForever;
    _animation.PlayQueued(shotAnimation.name, QueueMode.PlayNow);
    BroadcastMessage("Fire", shotAnimation.length); //Call Fire
    function in attached scripts of this GameObject or any of its
    children

    yield WaitForSeconds (shotAnimation.length);
    b_isShot = false;
    }

    private function WaitForPrepare () : IEnumerator {
    _animation[shotAnimation.name].speed = shotAnimationSpeed * 2;
    _animation[shotAnimation.name].wrapMode = WrapMode.
    ClampForever;
    _animation.CrossFade(shotAnimation.name, 0.6);

    yield WaitForSeconds(shotAnimation.length);
    b_isPrepare = true;
    }

    The preceding two functions are basically to play the aiming and shooting animation. Now, we are done with adding the New3PSController script.

  9. Then, go back to Unity and click on the First Person Controller object in the Hierarchy view, and go to its Inspector view; at the New 3PSController (Script) drag both objects that we just created, as follows:
    • Scope UI: ScopeUI (Drag ScopeUI object here)
    • Rocket Launcher : RocketLauncher (Drag RocketLauncher object here)

We are done with this section. Click Play to see the result. Now, if you hold the E key, the scope target will appear and our character will start playing aiming animation. If we let -click on the mouse while holding the E key, the character will start playing the shot animation. However, there is no rocket coming out right now. We will create the rocket and the particle object in the next section.

Objective Complete - Mini Debriefing

In this step, we just added some code to our New3PSController.js for controlling the aiming and shot animation as well as created the rocket launcher object and script that will trigger when the user presses fire or aim. We also created the GUITexture object to show the scope target graphic, which will show when the player presses E to aim and hide when the player doesn't press E.

In the Fire() function , we added the rocket launcher object. We checked for the time that our rocket will be fired at after the shot animation ended by checking for the reloaded time plus the last time that the character was shot. We also decreased the amount of bullet when the character clicks shot. In the next section, we will add the rocket prefab and the particle object in the Fire() function.

Classified Intel

If we take a look at New3PSController.js, we will see that we used the BroadcastMessage("Reload"); and BroadcastMessage("Fire", shotAnimation. length);. Both of these functions basically call all the functions named Reload or Fire, in this game object or any of its children. This is a great way to make our script and object more organized.

Performance wise, BroadcastMessage() is slower than a function call because it iterates through all possible target objects, finds matches of the desired function, and executes them. Therefore, it won't cause a huge increase in performance if we don't have a large number of function calls.

We can have different scripts attached to the children of this object and trigger at the same time. For example, BroadcastMessage("Fire", shotAnimation.length) will call the Fire(var f:float) function in each component at ached to the object (irrespective of whether we're calling it on the Component or the GameObject ). So, when the user hits fire, we will have the rocket shot at the same time with the smoke coming out from the launcher without having to code everything in one big script. We can see more details from the following links:

http://unity3d.com/support/documentation/ScriptReference/Component.BroadcastMessage.html.
http://unity3d.com/support/documentation/ScriptReference/GameObject.BroadcastMessage.html.

Next, we will take a look at the waitForShot() function, we will see that we use _ animation.PlayQueued(shotAnimation.name, QueueMode.PlayNow); instead of the CrossFade() function. This is because we want to play the shot animation as soon as the player presses fire. The PlayQueued() function will help us to fade between the same animation smoothly. We can see further details of this function from the following website:

http://unity3d.com/support/documentation/ScriptReference/Animation.PlayQueued.html

Unity 3 Game Development Hotshot Eight projects specifically designed to exploit Unity's full potential
Published: August 2011
eBook Price: $29.99
Book Price: $49.99
See more
Select your format and quantity:

 

(For more resources on this subject, see here.)

Creating the rockets and particles

In this section, we will continue creating the rockfet prefab, which will shoot out from the launcher. We will also create the trail smoke the follows this rocket, the smoke from the launcher barrel, and the explosion when the rocket hits something.

Engage Thrusters

We will start with creating the SmokePosition, which is the position of the smoke particle when the character first the rocket.

  1. Go to the Unity editor to create the smoke position by going to GameObject | Create Empty to create an empty game object and name it SmokePosition, and drag it inside the gun object, which is a child of the robot object, as shown in the following screenshot. By doing this we will break the prefab again, so we just click on continue to break it.

    Unity 3: Building a Rocket Launcher

  2. Then, we set Transform as follows:
    • Position: X: 1.5, Y: -0.08, Z: 0.25
    • Rotation: X: 90, Y: 0, Z: 0
    • Scale: X: 1, Y: 1, Z: 1

    Now, we got the smoke position from the launcher barrel.

  3. Next, create a smoke prefab object by going to the Project view, and click on the folder in this order: Standard Assets Particles | Smoke|, we will see Fluffy Smoke prefab, drag it to the Hierarchy view. Then, we will go to its Inspector view and start changing the parameters as follows:
    • Ellispsoid Particle Emitter:
    • Min Size: 0.5
    • Max Size: 0.75
    • Min Energy: 0.75
    • Max Energy: 1.5
    • Min Emission: 8
    • Max Emission: 12
    • Local Velocity: X: 0, Y: 0.75, Z: 0
    • Rnd Velocity: X: 0, Y: 0, Z: 0
    • Ellispsoid: X: 0.1, Y: 0, Z: 0.1
    • Particle Animator:
    • Color Animation[0]: R: 162, G: 162, B: 162, A: 0
    • Color Animation[1]: R: 147, G: 147, B: 147, A: 199
    • Color Animation[2]: R: 114, G: 114, B: 114, A: 143
    • Color Animation[3]: R: 126, G: 126, B: 126, A: 87
    • Color Animation[4]: R: 59, G: 59, B: 59, A: 0
    • Size Grow: -0.1
    • Rnd Force: X: 0, Y: 0, Z: 0
  4. Create the Smoke script by going to Assets | Create | Javascript and name it Smoke. Then, we go to the script and type the following code:

    public var timeOut : float = 0.5; // Destroy after 0.5 seconds.

    // Use this for initialization
    public function Start () : void {
    Invoke("KillObject", timeOut);
    }

    public function KillObject () : void {
    //Stop the emit the particle
    var emitter : ParticleEmitter = GetComponentInChildren
    (ParticleEmitter);
    if (emitter != null) {
    emitter.emit = false; // Stop Emit
    }

    //In here We set the particle to auto destruct to destroy
    itself after a life time (or we can setup it in the editor)
    var particleAnimator : ParticleAnimator =
    GetComponentInChildren(ParticleAnimator);
    if (particleAnimator != null) {
    particleAnimator.autodestruct = true;
    }
    }

    This Smoke script will be added to the Fluffy Smoke object that we just created. In this function, we use the Invoke() function , which will tell the script to call the KillObject() function after the timeout (0.5 seconds).

  5. Next, we will drag our Smoke script which we created to this Fluffy Smoke object (this will break the prefab again, so click on continue to break the prefab).
  6. Now, create a new prefab for our new Fluffy Smoke object by going to Assets Create | Prefab| and name it ShotSmoke. Then, drag the Fluffy Smoke object in the Hierarchy view to the ShotSmoke prefab in the Project view. Finally, we remove the Fluffy Smoke object in the Hierarchy view by right-clicking on the Fluffy Smoke object in the Hierarchy view and choosing Delete; now we have the new ShotSmoke prefab.
  7. Create the rocket prefab by dragging the rocket (FBX) model in the Project view, inside (Chapter5/Rocket) to the Hierarchy view.
  8. Click on the rocket model and go to its Inspector view to remove the Animation by right-clicking and choosing Remove Component. (This will bring up the losing prefab pop-up, so we just click Continue to break the prefab.)

    In Unity, every imported FBX model will have the Animation component at ached to itself automatically, but for our rocket, we don't need to use the Animation component, so we removed it from our model.

  9. We will now create the Rocket script , so go to Assets Create | Javascript| and name it Rocket; double-click on it to open MonoDevelop. Then, go to the script and replace the code as follows:

    @script RequireComponent(ConstantForce)

    public var timeOut : float = 3.0; // Destroy after 3.0 seconds.
    public var explosionParticle : GameObject;


    // Use this for initialization
    public function Start () : void {
    Invoke("KillObject", timeOut);
    }

    public function OnCollisionEnter (others : Collision) : void {
    //Create the explosion on the first impact point of the
    rocket and collider
    var contactPoint : ContactPoint = others.contacts[0];
    var rotation : Quaternion = Quaternion.FromToRotation
    (Vector3.up, contactPoint.normal);
    GameObject.Instantiate(explosionParticle, contactPoint.point,
    rotation);

    KillObject();
    }

    public function KillObject () : void {
    //Stop the emit the particle
    var emitter : ParticleEmitter = GetComponentInChildren
    (ParticleEmitter);
    if (emitter != null) {
    emitter.emit = false; // Stop Emit
    }

    //In here We set the particle to auto destruct to destroy
    itself after a life time (or we can setup it in the editor)
    var particleAnimator : ParticleAnimator =
    GetComponentInChildren(ParticleAnimator);
    if (particleAnimator != null) {
    particleAnimator.autodestruct = true;
    }

    //Detach the trail renderer in our praticles
    transform.DetachChildren();

    //Destroy this Object
    GameObject.Destroy(gameObject);
    }

  10. Next, add the Rocket script that we created by dragging the script to the rocket object in the Hierarchy.
  11. Then, go to the object's Inspector view to add the Box Collider to the rocket object by going to Component Physics | Box Collider|.

    When we add the Box Collider to the new object, the Box Collider will automatically adjust its size to fit around the object. This is why we don't have to set up the size or the position of the Box Collider.

  12. Then, we go to the Inspector view and set the following:
    • Transform
    • Position: X: 0, Y: 0, Z: 0
    • Rigidbody
    • Use Gravity: Uncheck (We don't need the gravity for our rocket)
    • Rocket (Script)
    • Explosion Particle: explosion (Drag the explosion built-in prefab in the Standard Assets Particles | Legacy Particles | explosion)|
  13. Next, we will add the built-in Smoke Trail prefab as a child of this rocket object. Go to the Project view, and click on Standard Assets Particles | Smoke| and drag the Smoke Trail prefab to the rocket object in the Hierarchy view.
  14. Then, we will click on the Smoke Trail object in the Hierarchy view and set the following in its Inspector view:
    • Transform: X:0, Y: 0, Z: -0.25
    • Ellispsoid Particle Emitter:
    • Min Size: 0.25
    • Max Size: 0.65
    • Min Energy: 0.75
    • Max Energy: 1
    • Particle Animator
    • Size Grow: 0.5
  15. Next, we will create a new prefab for our rocket object. Go to Assets | Create | Prefab and name it Rocket, and then drag our rocket object in the Hierarchy view to Rocket prefab, which we just created in the Project view. Finally, we remove the rocket object from the Hierarchy view by deleting it, and now we have the new Rocket prefab
  16. Go back to the RocketLauncher script by going to the Project view, double-click on the RocketLauncher script to go to MonoDevelop, and add the following new script at the beginning:

    public var smoke : GameObject;
    public var smokePosition : Transform;
    public var rocket : ConstantForce;
    public var speed : float = 10;
    public var ammoCount : int = 20;

    private var lastShot : float = 0.0;

  17. Go to the Fire() function and add the following highlighted code:

    public function Fire(_reloadTime : float) : void {
    if (Time.time > (_reloadTime + lastShot) && ammoCount > 0) {
    var rocketPrefab : ConstantForce = ConstantForce.
    Instantiate(rocket, transform.position, transform.rotation);
    rocketPrefab.relativeForce = new Vector3(0, 0, speed);

    var smoke : GameObject = GameObject.Instantiate(smoke,
    smokePosition.position, smokePosition.rotation);

    //We ignore the collision between rocket and character
    Physics.IgnoreCollision(rocketPrefab.collider, transform.
    root.collider);

    //Get the last shot time
    lastShot = Time.time;
    //Decrease the bullet
    ammoCount--;
    }
    }

  18. Go back to Unity and click on the First Person Controller object in the Hierarchy view. Then, go down two more steps inside this object until we see the RocketLauncher object , as shown in the following screenshot:

    Unity 3: Building a Rocket Launcher

  19. Click on the RocketLauncher object to bring up its Inspector view. Then set the following:
    • Rocket Launcher (Script)
    • Smoke: ShotSmoke (Drag the ShotSmoke prefab that we created in the Project view here)
    • Smoke Position: Smoke Position (Drag the SmokePosition object inside the gun child in the Hierarchy here)
    • Rocket: Rocket (drag the Rocket prefab that we created in the Project view here)

Now, we can click Play to see the result. We should be able to walk around by pressing the arrow, W, A, S, D, or Space key to jump, move the mouse to rotate around, press E to aim, press R to reload the rocket, and click on the let mouse but on to fire the rocket. However, we won't be able to see the number of bullets right now, because we don't have any UI set up to show the number yet. So, in the next step, we will create a bullet count UI by using GUITexture and OnGUI().

Objective Complete - Mini Debriefing

In this section, we just created the rocket and particle effect that will appear when the player presses fire. It seems like a lot to do in one section, but it was worth it.

First, in the Rocket script , we used @script RequireComponent(ConstantForce) to tell the script to require the ConstantForce for this rocket; this will tell Unity to basically add the ConstantForce automatically when we add this script to the object.

ConstantForce is one of the Physics components in Unity that will add a constant force to the RigidBody object (the ConstantForce works with the RigidBody components, so when we add the ConstantForce to our object, Unity will automatically add the RigidBody as well), which will contain the properties that we can use to control the rocket movement. For more details please have a look at the following website: http://unity3d.com/support/documentation/Components/class-ConstantForce.html.

Next, we have the timeout and explosion parameters. We then have the Invoke() function calling the KillObject() function at er the timeout (3.0 seconds). Then, we check for the collision object—if the rocket hits something, it will get to the position where the collision occurs, add the explosion object to that position, and then the rocket object will kill itself.

The KillObject() function basically stops the particle emitter, makes sure that the particle will destroy itself by setting the autodestruct parameter to true, detaches the particle, and destroys the game object itself.

Now, we create the script for the rocket and smoke particle. Then, we use the built-in particle package and adapt to the way we want for smoke and smoke trial. Finally, we put everything together and get the result as expected.

Classified Intel

In this section, we used the Instantiate() function to clone a new game object from the prefab object in the Project view. The Instantiate() function takes three parameters, which are the original Object, Position (Vector3), and Rotation (Quaternion). The Position and Rotation objects are the transform parameters at the start position of the object, which will be created in the scene. The Instantiate() function can take any kind of object and the result can also be returned to any kind of objects. We can also see more examples and details from the Unity document at

http://unity3d.com/support/documentation/ScriptReference/Object.Instantiate.html
http://unity3d.com/support/documentation/Manual/Instantiating%20 Prefabs.html.

Next, we will talk about the Invoke() function, which we used to call the function at er the time we have set in seconds. If some of you have experience with Actionscript, this function is very similar to the setTimeOut() function . We can also use InvokeRepeating() to call the method similar to the Invoke() function, but this function will repeat calling that function every time we set in seconds. We can see more details about the Invoke() function from the Unity document at:

http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.Invoke.html.

Finally, let's talk about the position of the rocket that launches from the same position of the scope target UI. This is a bit tricky because we want the player to be able to aim and shoot the rocket exactly to the same position that he/she is aiming at. So, we add the RocketLauncher object as a child of the Main Camera because we want it to move or rotate with the user view, which is the Main Camera. Then, we add the scope target UI at the center of the screen because it is easier for the player to aim than than if we put it on one side. So, we set up the positions X and Y of RocketLauncher object to 0 because it is the same position to the Main Camera and if we get the position of the Main Camera to the screen position it will be the center of the screen. Then, we set up the Z position of RocketLauncher object to 2 because it is the same depth as our character weapon graphics. This is to make the rocket not too close to the camera. We can also see it from the following diagram:

Unity 3: Building a Rocket Launcher

Creating the rocket bullet UI

Here we are at the last section of this article. As we know from the last step, we need a way to show the number of rockets let on the screen. In this step, we will create the rocket UI, which will show the number of rockets let and the rocket graphics. We will use both GUITexture and OnGUI() to create the UI.

Engage Thrusters

This is the last section, which will create the RocketUI script to display the remaining rocket bullets on the screen:

  1. Go to Assets Create | Javascript |and name it RocketUI. Then, double-click on it to open MonoDevelop and replace the script as follows:

    public var rocketLauncher : RocketLauncher;
    public var customSkin : GUISkin;
    public var width : float = 80;
    public var height : float = 25;
    public var pixelShift : int = 2;

    public function OnGUI() : void {
    GUI.skin = customSkin;
    DrawShadowText(new Rect(Screen.width*transform.position.x,
    (Screen.height*(1.0 - (transform.position.y - 0.005))), width,
    height),
    rocketLauncher.ammoCount.ToString(), customSkin.GetStyle
    ("RocketText"), Color.white);
    }

    //Draw a 45 degree black shadow text by shifting 2 pixel
    bottom-rightpublic function DrawShadowText (position : Rect,
    text : String, style : GUIStyle, textColor : Color) : void {
    var backupStyle : GUIStyle = style;
    //Draw a Shadow Text
    style.normal.textColor = Color.black;
    //Shift 2 pixel left and 2 pixel bottom
    position.x += pixelShift;
    position.y += pixelShift;
    GUI.Label(position, text, style);
    /////////////////////////////////////////////
    //Draw a Text
    style.normal.textColor = textColor;
    //Shift pixel back
    position.x -= pixelShift;
    position.y -= pixelShift;
    GUI.Label(position, text, style);
    style = backupStyle; // Set style back
    }

  2. Now, go back to Unity editor. Create the new GUISkin by going to Assets Create | GUI Skin| and name it CustomSkin; then click to bring up its Inspector view and set the following:
    • Font: Federation (Drag the Federation font in Chapter5/Fonts folder here)
    • Custom Styles
    • Size: 1
    • Element0
      • Name: RocketText:
      • Normal
        • Text Color: R: 255, G: 255, B: 255, A: 255
      • Font: Federation
      • Font Size: 20
      • Font Style: Bold
    • Other than the parameters mentioned earlier, we will leave everything as default.

  3. Next, create the new GUITexture object by going to GameObject | Create Other | GUI Textureand name it as RocketUI. Next, we drag our RocketUI script, which we just created on this object. Then set the following:
    • Transform: Position: X: 0.91, Y: 0.08, Z: 0
    • GUITexture:
    • Texture: rocket UI (Drag the rocketUI.png in the Chapter5/UI folder from the Project view here)
    • Pixel Inset: X: -64, Y: -32, Width: 128, Height: 64
    • Rocket UI (Script)
    • Rocket Launcher: RocketLauncher (Drag RocketLauncher child of the First Person Controller here)
    • Custom Skin: CustomSkin (Drag the CustomSkin that we just created in the Project view here)
  • Transform
    • Position
      • X: -0.8, Y: -0.8, Z: 1.4
    • Rotation
      • X: 0, Y: 10, Z: 0

We are now done with this article. We can click Play to see the result, and now if we press the R key to reload the bullet, we will see the number changes to 20 as we set the maximum number of bullets.

Objective Complete - Mini Debriefing

We just created the UI to show the rocket graphics UI and the number of bullets let by using GUITexture and OnGUI(). Here, we also created the text with a shadow by drawing another text layer and shifting the position bottom-right 2 pixels each, and then we drew the top layer by using the default position and color.

Classified Intel

In Unity, there is no easy way to create an outline or shadow for the dynamic text that can be easily adjustable like other sot ware such as Flash, Photoshop, and so on. So we can create it by drawing another layer to act as the outline of the shadow, as we did for the onGUI() function in this article.

This is not the best way to create the outlined text or the shadow text because if we adjust the size of the pixel by shifting more than 2 pixels, we will see that the background text shifts too much and doesn't look like the outline or shadow, as we can see in the following screenshot:

Unity 3: Building a Rocket Launcher

In this section, we can just use this technique to create the shadow or outlined text because it is a quick way to create the outline or shadow for the dynamics text.

To create the outlined text, we just create four text labels and shift each corner, top-left, top-right, bottom-left, bottom-right like we did for creating the shadow, and then create the last text labels on the top layer

Unity 3: Building a Rocket Launcher

So, let's take a look at the following screenshot of what we have done so far:

Unity 3: Building a Rocket Launcher

The preceding screenshot shows the camera view of the character.

Unity 3: Building a Rocket Launcher

The preceding screenshot shows the character shooting.

Unity 3: Building a Rocket Launcher

The preceding screenshot shows the rocket hitting the obstacle.

Summary

In this article, we have created the Resident Evil camera game style by adapting the built- in First Person Controller. We have also learned how to set up the FPS Character Controller, created the New3PSController script to control the character animation, created a rocket launcher, created the rocket prefab, and used the built-in particle to create the smoke from the launcher barrel, smoke trial from the rocket, and the explosion.

Next, we also learned how to use the Instantiate() function to clone the game object and display it in the scene. Then, we use Invoke() to call the function after the time that we assigned. Lastly, we created the UI to track the number of rockets let by using GUITexture and the OnGUI() function .


Further resources related to this subject:


About the Author :


Jate Wittayabundit

Jate was born in Bangkok, Thailand in 1980 and has a passion for both arts and mathematics. He received a Bachelor’s Degree of Architecture in 2003 and used to be an interior architect for several companies. Then,he came to Ottawa, Canada in 2005 and graduated from the Game Development program at Algonquin College in 2008.

Since he graduated from the Game Development program, he started working at Launchfire Interactive Inc. (http://www.launchfire.com) as a Flash Actionscript Programmer and developed many games and interactive contents (for the client such as Dell, Alaska Airline, etc.). In 2009, he decided to move to Toronto, bigger city, to get more chances to work in Game industry. He started a new position as a Game Developer & 3D Artist at Splashworks.com Inc. (http://www.splashworks.com). At Splashworks, he had a great chance to work with many different games and clients (such as, Shockwave, Swiss Chalet, and so on). It also gave him a chance to get to know Unity3D and love just how friendly UI is and how fast the workflow is.

The first video game he ever played was “Super Mario Bros.” and he has loved playing games ever since. He believes that being an Architect is also his strength; it supports his concepts and ideas of how the real world could apply in the virtual world.

In his spare time, he loves to work on 3D software, such as Zbrush, or 3D Studio Max. He also loves painting and drawing. Currently, he's trying to marry his architectural and 3D skills with his game development skills to create the next innovation game.

His website – http://www.jatewit.com

His Zbrush Character - http://www.zbrushcentral.com/showthread ... ight=tyris

Books From Packt


CryENGINE 3 Cookbook
CryENGINE 3 Cookbook

Unity 3D Game Development by Example Beginner's Guide
Unity 3D Game Development by Example Beginner's Guide

XNA 4.0 Game Development by Example: Beginner's Guide
XNA 4.0 Game Development by Example: Beginner's Guide

HTML5 Games Development by Example: Beginner’s Guide
HTML5 Games Development by Example: Beginner’s Guide

Flash Game Development by Example
Flash Game Development by Example

Panda3D 1.6 Game Engine Beginner's Guide
Panda3D 1.6 Game Engine Beginner's Guide

ZBrush 4 Sculpting for Games: Beginner's Guide
ZBrush 4 Sculpting for Games: Beginner's Guide

Away3D 3.6 Cookbook
Away3D 3.6 Cookbook


No votes yet

Post new comment

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
w
x
U
f
u
4
Enter the code without spaces and pay attention to upper/lower case.
Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software