I have two animation clips for a door, one is open and the other is close. I check the default animation clip name to judge the door is open or close, if it is open, after I close it, I set the default animation to close; if it is closed, after I open it, I set the default animation to open. I just can not find which function I can use to change the default animation by script.
Well you could define the clip to be used first in the start function, and then use a boolean like IsOpen=true; type thing so
OnTriggerEnter(player: Collider){
if(player.name==("whatever")&IsOpen==false(Input.GetKey("Enter"))){
//play open animation
}
Thats a really messy general pointer, that probably wont compile and you need to fiddle around getting the right brackets in the right place, but hopefully you get the idea
Thanks for the solution. That’s what I am doing now, but I think this method is not good enough because you have to have a variable in the game, I mean, you have to put this variable into a global class to check it whenever you’re triggered.
I just wonder how I can change the default animation from “open” to “close” shown in this image so that I can check
if(animation.clip.name == "open")
{
...
}
to know whether the door is opn or close, if the default animation is “open”, I close the door by using
animation.Play();
after that, I set the default animation to “close” for next round.
I just wonder how to change this default animation to what I want by scripting.
Seems no one can answer my question to read the default animation value from Inspector. So I have to add some global variables to take care of it. But I still think there should be a way to read the value. :?: