Hi there, I’m very basic when it comes to scripting in Unity, and all I want to do is make an elevator button. Right now, when I hit the button, the elevator going up animation plays, and the cube that is the button turns green. I need to do a few more things, and have NO idea how ><
First, I need the cube-button to be a grey color before the button is pressed, and revert back to grey after the Animation is finished, to show the elevator is on that floor. Right now it is standard grey-box grey, not the Color.grey.
Afterwards, I need to be able to make the elevator go down when i stand on it. This can be done in a trigger, I should be okay with this though.
Really, it’s this button and the whole part on when Animations End that stumps me.
There is no default callback for Animation ending. There are a few ways to manage this- the first is to add an Animation Event to the last frame of the animation, and use that to handle the event, but this requires manually editing all of your animations in Unity's animation editor (which is honestly pretty painful). They way I prefer to do this, is to set off a coroutine at the same time as I start the animation, which waits for animation[currentClip].length, and then calls a method.
animation.Play("elevatorUp");
StartCoroutine(WaitAndCallback(animation["elevatorUp"].length));
IEnumerator WaitAndCallback(float waitTime)
{
yield return new WaitForSeconds(waitTime);
AnimationFinished();
}
void AnimationFinished()
{
// Turn the light back grey again!
}
Here's a version for people who can't translate between C# and UnityScript:
animation.Play("elevatorUp");
WaitAndCallback(animation["elevatorUp"].length);
function WaitAndCallback(waitTime : float)
{
yield WaitForSeconds(waitTime);
AnimationFinished();
}
function AnimationFinished()
{
light.renderer.material.color = Color.gray;
// Turn the light back grey again!
}
One thing that I don't understand about your question- what's the difference between 'default grey' and 'Color.grey'? Aren't they both the same colour?