Create a new empty game object and rename it to Bolt and
reset its transform then create a quad and name it VFX and reset its transform
as well them add it as a child of bolt. Change the transform rotation X-axis of
VFX to 90, to rotate it upwards to the camera. Now we need an image for the
bolt, in the materials folder create material which makes a new material in the
materials folder and rename it to fx_bolt_orange. Next drag the texture onto
the newly created material to apply that texture to it. Now drag the material
onto the quad. Once again, we need to change the shader of the material to
particles, additive. Now select the Bolt parent and add component, physics,
rigidbody and deselect use gravity, reselect VFX and remove the mesh collider
component then back to the Bolt parent and add component physics, capsule
collider. Change the direction to Z-axis then resize the collider via the
radius and height to match the Bolts size and select the Is Trigger box. Still
in the Bolt parent add another component, Script, new script and name it Mover
and place it into the scripts folder then open it up in monoDevelop.
Public class Mover : MonoBehaviour
{
Public float speed;
Void start ()
{
GetComponent<rigidbody>().velocity = transform.forward
* speed;
}
}
Move the Bolt and VFX assets to prefab and select the Bolt
and change the speed to 20 since the ships speed is set to 10 currently, now
delete bolt from the hierarchy and click play then click and drag the bolt in
the prefab into hierarchy and you can see copies of the bolt being fired while
the game is running.
Now we need to create a boundary so that the bolts can
despawn after going a certain distance. Create new game object 3D cube and name
it Boundary and make sure its at origin. On the box collider component make
sure Is Trigger is selected/checked, now set the transform position Z-axis to 5
and the transform scale X-axis 15 and Z-axis 20, then deselect Mesh Renderer so
that you cannot see the box when playing the game. With Boundary selected add
component, script, new script and name it DestroyByBoundary and place it in the
scripts folder and now open the script.
Public class DestroyByBoundary : MonoBehaviour
{
Void onTriggerExit(Collider other) {
Destroy(other.gameObject);
}
}
Comments
Post a Comment