x


Toggle GUI button to play, and then reverse animation

Is it possible to create a GUI button that will play an animation (something appears on a terrain - like a bunch of buildings) and then the second click would reverse the animation (or would call a second animation up that would remove the objects from the terrain). Current script being used - and failing - is:

var cube1 : GameObject;


var customSkin : GUISkin;
var toggle = false;

var image : Texture;

function OnGUI () {
GUI.Box (Rect (0,0,210,425), "Cubes");

GUI.skin = customSkin;

toggle = GUI.Toggle (Rect (10,40,40,40),toggle, image, "button");
cube1.animation.Play("cube1move");

Thanks!

more ▼

asked Oct 13 '10 at 02:21 PM

DvdRB gravatar image

DvdRB
5 6 6 11

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

1 answer: sort voted first

Here's an example I used for a door (with trigger). The tricky thing was that it continued playing backwards from 0. That's why this is a bit complicated: Basically, you can reverse the animation with animation["animationName"].speed = -1.0;.

function OnTriggerEnter (other : Collider) {
    if (other.tag == "Player") {
        animation["DoorSlide"].speed = 1.0;
        if (!animation.isPlaying) {
            animation.Play();
        } else {
            if (animation["DoorSlide"].time < 0.0) {
                animation["DoorSlide"].time = 0.0;
            }
        }


    }
}

function OnTriggerExit (other : Collider) {
    if (other.tag == "Player") {
        animation["DoorSlide"].speed = -1.0;
        if (!animation.isPlaying) {
            animation["DoorSlide"].time = animation["DoorSlide"].length; 
            animation.Play();
        }
    }
}

You should be able to do something similar with GUI-Elements. I hope this helps!

more ▼

answered Oct 13 '10 at 02:53 PM

maikkel gravatar image

maikkel
204 15 17 25

(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:

x3698
x224
x162
x36

asked: Oct 13 '10 at 02:21 PM

Seen: 1817 times

Last Updated: Oct 13 '10 at 02:21 PM