Script :)

Hi can someone help me with the script
I want like when i press “Fire1” i will drop C4 but it waits like for a 3 seconds for animation that i made to finish then drops C4
“Like its tiping the code when it’s finish it will drop”

var bomb : Transform;

function Update() {
    if(Input.GetButtonDown("Fire1")) {
	animation.Play("C4");
	yield WaitForSeconds (1) ; 
        bomb.parent = null;
        bomb.rigidbody.isKinematic = false;
        bomb.rigidbody.velocity = rigidbody.velocity;

    }
}

function FixedUpdate () {
    rigidbody.AddForce(Vector3.forward);
	
}

But it doesn’t work i press “Fire1” and nothing happents. Help please :slight_smile:
Thank you. :slight_smile:

if(Input.GetButtonDown(“Fire1”))… is a mouse click… not “g”

I changed that.But it doesn’t work

I just tiped it wrong in text.

Try something like:

var bomb : Transform;
var wait : int;

function Update() {
    if(Input.GetButtonDown("Fire1")) {
	animation.Play("C4");
	wait=1; 
        WaitBeforeDrop();
      

    }
}

function WaitBeforeDrop(){

if (wait==1){
        yield WaitForSeconds(3);
        bomb.parent = null;
        bomb.rigidbody.isKinematic = false;
        bomb.rigidbody.velocity = rigidbody.velocity;
        wait=0;
}
}

function FixedUpdate () {
    rigidbody.AddForce(Vector3.forward);
	
}

May require a bit of tweaking though…

Thanx.It works