controlled explosion

i have an onCollideExplode code.

how can i get it to explode on key input (Fire) instead of by collision?

mu code:

CODE>>

using UnityEngine;
using System.Collections;

public class OnCollideExplode : MonoBehaviour
{

// A grenade
// - instantiates a explosion prefab when hitting a surface
// - then destroys itself
public GameObject explosionPrefab;
public float explodeSecs = -1;

void Awake()
{
if(explodeSecs > -1) Invoke (“DestroyNow”, explodeSecs);
}

void OnCollisionEnter( Collision collision )
{
// Rotate the object so that the y-axis faces along the normal of the surface
ContactPoint contact = collision.contacts[0];
Quaternion rot = Quaternion.FromToRotation(Vector3.up, contact.normal);
Vector3 pos = contact.point;
Instantiate(explosionPrefab, pos, rot);
// Destroy the projectile
Destroy (gameObject);
}

void DestroyNow()
{
Instantiate(explosionPrefab, transform.position, transform.rotation);
Destroy (gameObject);
}

}

CODE>>

Check for the intended input per-frame and trigger your explosion.

void Update () {

if (Input.GetButtonDown("Fire1")) {

DestroyNow();

}

}

where on the code do i place this?

using UnityEngine;
using System.Collections;

public class OnCollideExplode : MonoBehaviour
{

// A grenade
// - instantiates a explosion prefab when hitting a surface
// - then destroys itself
public GameObject explosionPrefab;
public float explodeSecs = -1;

void Awake()
{
if(explodeSecs > -1) Invoke ("DestroyNow", explodeSecs);
}

void OnCollisionEnter( Collision collision )
{
// Rotate the object so that the y-axis faces along the normal of the surface
ContactPoint contact = collision.contacts[0];
Quaternion rot = Quaternion.FromToRotation(Vector3.up, contact.normal);
Vector3 pos = contact.point;
Instantiate(explosionPrefab, pos, rot);
// Destroy the projectile
Destroy (gameObject);
}

void DestroyNow()
{
Instantiate(explosionPrefab, transform.position, transform.rotation);
Destroy (gameObject);
}


// added here
void Update () {

if (Input.GetButtonDown("Fire1")) {
     
    DestroyNow();
     
    }     
}

}

ok it works. but how can i get it to not explode on collision?

Delete all this:

void OnCollisionEnter( Collision collision )

{

// Rotate the object so that the y-axis faces along the normal of the surface

ContactPoint contact = collision.contacts[0];

Quaternion rot = Quaternion.FromToRotation(Vector3.up, contact.normal);

Vector3 pos = contact.point;

Instantiate(explosionPrefab, pos, rot);

// Destroy the projectile

Destroy (gameObject);

}

thanx

ok im now running into this problem

Assets/SteelAwakining Assets/JUNO Scripts/OnCollideExplode.cs(6,18): error CS0101: The namespace global::' already contains a definition for OnButtonChange’

I do believe that means you have two or more scripts with this:

public class OnButtonChange: MonoBehaviour

they all need to be unique.