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");
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!