I am trying to code a script which acts as dynamite. I have the dynamite with a sphere collider attached acting as a trigger.
public class DynamiteScript : MonoBehaviour {
public float startTime=0.0f;
public float destroyTime=2.0f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter(Collider collision)
{
startTime += Time.deltaTime;
if (startTime>destroyTime)
{
Destroy(collision.gameObject);
}
}
}
How do i alter this so that after 2 seconds any objects in the collider with tag Enemy are destroyed and also destroys the dynamite game object as well. Is it possible to make an explosion as well?