Game Development Reference
In-Depth Information
1. using UnityEngine;
2. using System.Collections; 3.
4. public class RocketLauncher : MonoBehaviour { 5.
6.
//Prefab of the rockets the shuttle launches
7.
public GameObject rocket;
8.
9.
void Start () { 10.
11.
}
12.
13.
void Update () {
14.
//We use spacebar (discrete presses) for rocket launching
15.
if(Input.GetKeyDown(KeyCode.Space)){ 16.
17.
//How many rockets there are in the scene?
18.
TargetFollower[] rockets =
19.
FindObjectsOfType<Tar-
getFollower>();
20.
21.
//Do not allow more than one rocket at the same time
22.
if(rockets.Length == 0){
23.
//Create new rocket at the position of the
24.
//shuttle and at the same rotation of it
25.
Instantiate(rocket,
26.
transform.position, transform.rotation);
27.
}
28.
}
29.
}
30.}
Listing 23: Rocket launching script
Search WWH ::




Custom Search