- Home /
BULLET DOES NOT EXPLODE WHEN HIT THE ENEMY
// Instantiates a projectile every 0.1 seconds,
// if the Fire1 button is pressed or held down.
var projectile : Rigidbody;
var fireRate = 0.1;
var Velocity : float = 25;
private var nextFire = 0.0;
function Update () {
//If the player holds down or presses the left mouse button
if (Input.GetButton ("Fire1") && Time.time > nextFire) {
Shoot();
}
}
//To make our scripting a little more Object-Oriented-Programming, we will create our custom functions as well
function Shoot() {
//Add fireRate and current time to nextFire
nextFire = Time.time + fireRate;
//Instantiate the projectile
clone = Instantiate (projectile, transform.position, transform.rotation);
//Name the clone "Shot" ::: this name will appear in the Hierarchy View when you Instantiate the object
clone.name = "Shot";
//Add speed to the target
clone.rigidbody.velocity = transform.TransformDirection (Vector3.forward * Velocity);
}
when i shot the enemy bullet does not explode, ı want to see an effect while exploding. if all my script has any problem, could you tell me all steps one by one
This code has nothing to do with the bullet or the bullet hitting the enemy... This is the script that fires the bullet.
NO IDEA I COULDN'T READ YOUR SCRIPT OVER THE LOUD SOUND OF YOUR CAPS
You wouldn't expect it to explode if you had any idea what the script you copied and pasted from the docs is doing. You need to do a lot more reading.
Answer by djm · Jun 20, 2012 at 05:45 PM
For an explosion you could create a particle system FX and add it to a Prefab. Use the Prefab as the Inspector Variable for a script that includes the explosion on impact.
//Inspector Variable
var explosion : Transform;
function OnTriggerEnter(other : Collider)
{
//Check for enemy
if(other.gameObject.tag == "enemy")
{
//Create the explosion on impact
if(explosion)
{
Instantiate(explosion, transform.position, transform.rotation);
}
//Destroy bullet
Destroy (gameObject);
}
}
Your answer
Follow this Question
Related Questions
Explode object after being shot based on health decreasing (particle explosion) 0 Answers
How do i get my object to explode and destroy? 2 Answers
Make tagged objects explode with ray cast? 1 Answer
oncollisionEnter help 2 Answers
Function action applies to every object that have script with that function on it. Help please 1 Answer