0

Game Creation with Unity – Part 3

Posted by Dr. Burton on December 23, 2010 in Game Development, Unity3D |

In part 1 of this tutorial we started a new Unity 3D project to create a space game with the goal of shooting asteroids.

In part 2, we added the controls to our player/ship so that it can move within the environment as well as the objects that will become our asteroids and bullets.

In this tutorial, we will cover adding the script for the bullet, making explosions, and a little bit of troubleshooting.

Video clip:

[tubepress video=54xjDMlOIrY]

Bullet Script:

var bulletSpeed:int;
var explosion:Transform;

function Update () {
amtToMove = bulletSpeed * Time.deltaTime;
transform.Translate(Vector3.forward * amtToMove, Space.Self);
if(transform.position.y > 50 || transform.position.x > 50 || transform.position.z > 50
|| transform.position.x < -50 || transform.position.y < -50 || transform.position.z < -50)
{
Destroy(gameObject);
}
}

function OnTriggerEnter(otherObject:Collider) {

if(otherObject.gameObject.tag==”astroid”) {
Player.playerScore +=100;
var tempExplosion:Transform;
tempExplosion = Instantiate(explosion, transform.position, transform.rotation);
Destroy(otherObject.gameObject);
Destroy(gameObject);
}
}

Part 4, Setting up win and lose, making a web deployment >

Tags: , , ,

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Copyright © 2010-2019 Burtons Media Group All rights reserved.
This site is using the Desk Mess Mirrored theme, v2.5, from BuyNowShop.com.