0

Game Creation with Unity – Part 2

Posted by Dr. Burton on December 15, 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 will be adding 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.

Clip 1:

[tubepress video =po6FkFt98Y4]

Player Script:

var playerSpeed:int;
var xSpeed = 250.0;
var ySpeed = 120.0;
private var x = 0.0;
private var y = 0.0;
var playerLives:int;
static var playerScore:int;

function Update () {
amtToMove = (playerSpeed * Input.GetAxis(“Vertical”)) *Time.deltaTime;
transform.Translate(Vector3.forward *amtToMove, Space.Self)
if (Input.GetMouseButton(1)) {
x+= Input.GetAxis(“Mouse X”) * xSpeed * 0.02;
y-= Input.GetAxis(“Mouse Y”) * ySpeed * 0.02;
var rotation = Quaternion.Euler(y,x,0);
transform.rotation = rotation;
}
}

function OnGUI() {
GUI.Label(Rect(10,10,200,50),”Score: “+ playerScore);
GUI.Label(Rect(10,30,200,50),”Lives: “+ playerLives);
}

On to Part 3, bullets, explosions, and troubleshooting! >

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.