- Home /
Playing door animation doesn't work.
Following script: using UnityEngine; using System.Collections;
public class DoorToggle : MonoBehaviour {
private bool doorOpen = false;
// Use this for initialization
void Start () {
}
void OnMouseUpAsButton () {
if (doorOpen) {
gameObject.animation.Play("Close");
}
else {
gameObject.animation.Play("Open");
}
doorOpen = !doorOpen;
}
void OnGUI() {
GUI.Box(new Rect(32,32,100,24),doorOpen.ToString());
}
// Update is called once per frame
void Update () {
}
}
doesn't work. Code gets executed as doorOpen is changing values, but it doesn't work.
Door were animated in Blender, closing/opening animations are like 60 frames (1sec). I've tried to use Play, PlayQueued and even crossfade, none of these are working.
Have you imported animations from blender?
do you see them in inspector/do the work?
Did you split the animation from blender?
Not sure, but maby capitalization matters. Check the names of animations.
Try leaving out 'gameObject.' from your animation call.
Yes, I did.
Yes.
Yes, though I'm not sure if I did it correctly. From 1 (key frame, kf) frame to 60 (kf) there is opening animation (just rotating by 90), from 61 to 120(kf) there is closing animation. Then I manually split animation into "Open" and "Close" animation under animations tab (aside of that all settings are default)
Capitalization was first thing I check. It is Open and Close (first capital letter) and was correct.
Answer by YoungDeveloper · Sep 19, 2013 at 07:51 AM
Try switching the animation type to Legacy, It's located in objects inspector Rig tab.
Tried that, made it worse (door either turned invisible or moved so faar that they could be just as well invisible). I'm always trying to search/solve problems on my own before posting, but this issue is bugging me.
Try running On$$anonymous$$ouseUpAsButton (); in start function, see if that works, if yes, the problem is in registering mouse activity.
If you missed that (no sarcasm or insult intended), I've already checked if On$$anonymous$$ouseUpAsButton gets executed and it does (doorOpen bool changes value when door are clicked (as seen in debug gui I've made inside script), and doorOpen is only changed in On$$anonymous$$ouseUpAsButton.
Answer by clunk47 · Sep 19, 2013 at 05:00 PM
Be sure that before importing to Unity: In Blender, select your door object, hit CTRL + A, then apply Rotation and Scale. Then use Legacy Rig, under Generation, select Store In Root(New).
Your answer
Follow this Question
Related Questions
Children won't animate 2 Answers
Blender to Unity - Child Of Bone Constraint With FPS Reload Animation 0 Answers
What exactly can i do with Mecanim? 1 Answer
Importing assets 0 Answers
Animation Problems 1 Answer