Game Creation with Unity – Part 3


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 >

Recent Posts