Game Development Reference
In-Depth Information
2. Then, go to the Inspector view of the RocketLauncher to set up the Transform
| Position , X: 0 , Y: 0 , Z: 2 . Next, we create the GUITexture for the scope target by
going to GameObject | Create Other | GUI Texture and naming it ScopeUI . Go to
its Inspector and set the following:
F GUITexture
Texture : scopeTarget.png ( Chapter5/UI folder/
scopeTarget )
Pixel Inset
X: -16 , Y: -16 , Width: 32 , Height: 32
3. Create a new RocketLauncher script by going to Assets | Create | Javascript and
name it RocketLauncher , double-click on it to open MonoDevelop . Then, go to
the script and replace the code as follows:
public var speed : float = 10;
public var ammoCount : int = 20;
private var lastShot : float = 0.0;
public function Fire(_reloadTime : float) : void {
if (Time.time > (_reloadTime + lastShot) && ammoCount > 0) {
//Get the last shot time
lastShot = Time.time;
//Decrease the bullet
ammoCount--;
}
}
public function Reload () : void {
ammoCount = 20;
}
Here, we create the Fire and Reload() funcions to trigger when the user
presses R to reload the bullet or presses E to aim, which will be called from
New3PSController .
4. Go back to Unity and go to the Project view and drag your RocketLauncher script
to the RocketLauncher object in the Hierarchy view.
 
Search WWH ::




Custom Search