Game Development Reference
In-Depth Information
var rocketPrefab : ConstantForce = ConstantForce.
Instantiate(rocket, transform.position, transform.rotation);
rocketPrefab.relativeForce = new Vector3(0, 0, speed);
var smoke : GameObject = GameObject.Instantiate(smoke,
smokePosition.position, smokePosition.rotation);
//We ignore the collision between rocket and character
Physics.IgnoreCollision(rocketPrefab.collider, transform.root.
collider);
//Get the last shot time
lastShot = Time.time;
//Decrease the bullet
ammoCount--;
}
}
18. Go back to Unity and click on the
First Person Controller
object in the
Hierarchy
view. Then, go down two more steps inside this object unil we see the
RocketLauncher
object, as shown in the following screenshot:
19. Click on the
RocketLauncher
object to bring up its
Inspector
view. Then set
the following:
Rocket Launcher (Script)
Smoke
:
ShotSmoke
(Drag the
ShotSmoke
prefab that we created in the
Project
view here)
Smoke Position
:
Smoke Position
(Drag the
SmokePosition
object inside the
gun
child in the
Hierarchy
here)
Rocket
:
Rocket
(drag the
Rocket
prefab that we created in the
Project
view here)