Game Development Reference
In-Depth Information
Figure 6-6. 3 × 3 grid of nine Target game objects
Now that the target grid is in place, set up the projectile launcher. We will use the Main Camera as
the source for aiming and launching the projectiles. In the Project panel, select the Assets ➤ Scripts
folder, then Create ➤ Javascript and name the new script ProjectileLauncher. Double-click to open
for editing in MonoDevelop. Edit the ProjectileLauncher script to the following:
#pragma strict
public var projectile : GameObject;
public var cameraSpeed : float = 5;
function Update () {
var horiz : float = Input.GetAxis("Horizontal") * Time.deltaTime * cameraSpeed;
var verti : float = Input.GetAxis("Vertical") * Time.deltaTime * cameraSpeed;
transform.Translate(horiz, verti, 0);
if(Input.GetButtonUp("Fire1")) {
var projectileInstance : GameObject = Instantiate(projectile, transform.position,
transform.rotation);
Destroy(projectileInstance, 2);
}
}
Search WWH ::




Custom Search