x


falling block bridge

I have a bridge set up of 20 blocks. I have a script on my character that when he touches a button it starts. I want the bridge to fall 1 block at a time starting from one end to the other. what would be the best way to do this?

more ▼

asked Jul 30 '10 at 07:26 AM

theawesomesheep gravatar image

theawesomesheep
12 2 2 2

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Get an array of each block, in order, via script. Then something like this:

// C#
// Assumes you have "GameObject[] pieces;" already set up.

IEnumerator BridgeFall()
{
    for(int i = 0; i < pieces.Length; i++)
    {
        pieces[i].rigidbody.gravity = true;
        // or however you make them "fall".

        yield return new WaitForSeconds(1);
        // or however long you want to wait for.
    }
}

Then, just start the coroutine with StartCoroutine(BridgeFall()); whenever you wanted it to fall.

more ▼

answered Jul 30 '10 at 08:52 AM

qJake gravatar image

qJake
12.3k 44 80 165

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x7790
x5386
x2726

asked: Jul 30 '10 at 07:26 AM

Seen: 993 times

Last Updated: Jul 30 '10 at 07:26 AM