The Animation Editor is great and I understand how to use it to create animations. However, I can’t find any documentation on how to trigger the animations and use them in the game.
Is there a simple example somewhere on how to script to use the animations?
I’ve just discovered the animation isn’t being added to the object in the Inspector automatically as it says in the manual and I’m now dragging and dropping it from it’s saved folder in Assets so at least I’ve found it and managed to attach it.
Still a tutorial on using animations would be really appreciated.
The animation editor is basically creating an AnimationClip object. You can use animation.AddClip to add this clip to a script under a given name. You then use animation.Play to play the clip with the name you have set.
Thanks, I’ll have another go at those links and try and figure out what to do. The trouble is I’m not a scriptor and don’t know how to write a script that correctly uses those functions.
I got the Will Goldstone book with a view to learning and tried to adapt one of his scripts to use with the Animations created by the Animation Editor but although the sound effects worked when the firstperson controller met the box collider, the animation did not trigger. I don’t know how to go about altering the script to adapt it to the animation editors animations.
I have got this script working on a door animated in C4D but it’s not totally successful as there is some problem with the imported animation which is why I was really looking forward to the Animation Editor. Creating the Animations in the Editor is great, it’s very straightforward and you have excellent control. Better than C4D in fact.
In the manual for the Animation Editor it says the animations will appear in the Inspector for the object but I found that they didn’t. I have trouble saving the animations at all, often having to restart Unity just to get them to save and show up in the Assets folder. Then I had to drag and drop them from the Assets file I’d saved them to onto the object.
The script called for three animations; idle, dooropen, doorshut. So I created those but then had to figure out how to add them as although the Animation component had been added to the door object in the Inspector when I dragged the Idle animation onto the object it only had the one animation. I changed the number of animations in the component to 3 but although two more spaces for animations appeared, no drop down menu to add them with appeared which is what usually happens.
Eventually I dragged and dropped the dooropen and doorshut animations onto the spaces for them in the component and they seemed to stick. So the set up with the Animation Editor animations now looks the same as the object with the C4D animation but I can’t figure out why the Animation Editor animation doesn’t work.
What I need is some complete example scripts showing how to activate the animations to study and adapt.
HiggyB kindly said he would look into this and maybe get something posted somewhere but if you have any suggestions in the meantime that would be great.
I’ve found a short Java script course in the New Year but it’s all web stuff and I don’t know how much use it would be for Unity scripting but it seems like it would be better than nothing and might give me a starting point.
A neat way to access the animations is to add public variables of type AnimationClip to your script:-
var anim1: AnimationClip;
var anim2: AnimationClip;
Animation assets created by the animation editor are also AnimationClips so you can drag these files onto the public variables in the script. You can now access those AnimationClips in the script via the public variables. To make them available for playback, use animation.AddClip to add them under a suitable name:-
I’ve had a go at modifying the Will Goldstone script to make it work with the Unity animations.
I’ve tried to follow your instructions as best I can but my doors remain stubbornly uninterested.
If I put in the “animation.AddClip(anim1, “idle”);
animation.AddClip(anim2, “dooropen”); etc” bit anywhere I just get an error from the Console saying “There is no “Animation” attached to the “First Person Controller” game object, but a script is trying to access it” and all I can do is point to them in the FPC’s Inspector and shout “There you fool!”, which the Console doesn’t understand, and the doors still don’t open so I am missing something somewhere.
More info please, that isn’t enough to explain what you mean. There are three clips, idle, dooropen and door shut, you can see them in the pictures above.
I have the object tagged with a name. A similar set up works in another script.
OK, I tried to guess what you meant and tried using Anim2 etc where the names of the clips were in the script but then I just get an error from the Console about “Unknown identifier Anim2” so no further forward.
it’s a simple door opening script there must be some way to do it.