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! >