Does anyone know script for a C4 bomb like to drop it for like 10 seconds explode and to detonate it… ![]()
And like when i hold “f” for like 15 seconds it detonates.
Search the forums I remember someone asking that exact same question before… Save he also wanted to throw it…
The basics of a timed explosion would have you use yield WaitForSeconds (10); then have the explosion go off.
You could tell it to wait for 15 seconds if you press a certain key to drop it, or… when the person releases the key you can have it explode (not the best way to do it)
There are 2 basic ways to do this:
Using GameObject.SendMessage you can tell the explosive to explode. At that point you can say, has it been down for at least 10 seconds, if so, explode, if not, wait for the remainder of the time.
You could use the GetComponent(“ScriptName”).explosionKeyDown to ask the player that dropped it if he still has the key down (after the 10 seconds has expired)
Both ways achieve the same results.
Look at Invoke for delayed function calls.
var timeOut = 1.0;
var detachChildren = false;
function Awake ()
{
Invoke (“DestroyNow”, timeOut);
}
function DestroyNow ()
{
if (detachChildren) {
transform.DetachChildren ();
}
DestroyObject (gameObject);
}
Try this, it may help. I am new to unity. However, this is wait I use for my game to explode.
Ok.