#pragma strict
var trigger: GameObject;
function OnTriggerEnter(){
Debug.Log("animationtrial");
}
So when I walk into the trigger I get a message on the console saying ‘animationtrial’
So now I want to have an animation play
I create an empty object “AnimatedCube”
Then I create a Cube and scale
In the hierarchy I drag the cube inside the “AnimatedCube” object
animate the cube (windows>animate), record it and save it under name ‘anime’ - This is when in play mode by cube just moves forward and loops
in the same script above I just add this code
animation.Play(“anime”);
so
#pragma strict
var trigger: GameObject;
function OnTriggerEnter(){
Debug.Log("animationtrial");
animation.Play("anime");
}
But then I get this message
MissingComponentException: There is no ‘Animation’ attached to the “Trigger” game object, but a script is trying to access it. You probably need to add a animation to the game object “Trigger”. Or your script need to check if the component is attached before using it.
Trigger is basically my trigger the box collider.
So how do I add the animation to the trigger???
I mean the trigger is working, I debugged it and I’m getting a message, just want to have an animation triggered now.
Add the Animation component to what has the sound. Add the clip to the Animation component’s appropriate slot and then use “animation.Play()” to play the sound. Unity - Scripting API: Animation.Play
You can also get creative and dynamically change the sound using other functions under the Animation section. Also, if the trigger is not the same object, you’d have to find the object with the animation to play it. And my favorite way to do it is to put the trigger as a child of what holds the animation (if the trigger is on the object) and do something like “this.parent.animation.Play()”.
Hey thank you very much but I tried everything and it’s still just not working
All the tutorials I watch have the option of deselecting “automatically play” on the inspector and also my animation is looping when I don’t want it do.
In my inspector window it says “animator” but not animation as show on this video at 5:28 for example
I also have a door open animation in the door object as show in the image above highlighted in red but it keeps giving me the error I had before. I’m literally follow a tutorial on YouTube but it’s not working I just don’t know what to do.
Now I’m just trying to use this script from a tutorial
var doorClip : AnimationClip;
function OnTriggerEnter (player : Collider) {
if(player.tag==“Player”)
GameObject.Find(“Door”).animation.Play(“DoorOpen”);
}
EDIT: Ok I figured out how to stop the loop, I went into animator throguh window then double clicked the DoorOpen node and unticked ‘loop time’
Now I need to figure out how to not play the animation automatically and also why I have a different interface, I have animator instead of animation ):
There are two components (and also two different tools named the same under the Windows menu): Animator and Animation. No idea what Animator does (yet), but Animation is the component you need. Both are under Components → Miscellaneous
Ok I accessed it and will try now, let you know what happens.
But for some reason when people go to windows and select “animation” and then record their animation, on their inspector window they get “animation” while I get “animator”, do you know why? Maybe something I have to change via settings?
What I will do is I will record, will get “animator” and then tick it off and from components miscellaneous will add “animation”…
Exact same thing, there’s an “Animator” windows and “Animation” windows. One of these I will succumb to my curiosity and finally look up the difference between the two.
Yup, in Animation, you can record Animations. And double checked right now as well, in case I said anything wrong.
I forgot the difference, but the Animation in Unity is being/has been changed recently. “Legacy” refers to the “old” version of Animation if I recall correctly. Honestly, for simple animations that I made, I pretty much choose Legacy all the time because… I forgot what all but the Humanoid is meant for
Click on your imported asset (the whole object and such) and under Rig (in the Inspector) change Animation Type to Legacy using the drop-down menu then click Apply. Also, there are quite a few useful things in these three tabs for importing objects, so feel free to mess with them (carefully).
Also, to edit an animation clip (in Unity) you actually have to make a duplicate of the clip that lies within the import, and then edit THAT duplicate.
Did you try clicking on the animation clip you made (wherever it is, try using search for “DoorOpen” if you can’t find it)? It may have the options in there.
If you still can’t find-
This double post is just in case you’re testing this out at the moment:
That link I gave above (if I read it slowly enough this time) gives the same exact instructions as before. Here’s a better one:
ok so I changed this now I will try to animate it I’m going to go bed now thanks so much I will keep trying will let you know if I have problems and stuff probably Monday
thanks again i did learn quite a lot still trying to fix it ):
I change it to 1 so now I add the DoorOpen to the cube or door but nothing still happens
Ya it’s a bit confusing, but I’ve actually been using BOTH the legacy animations and the new mecanim animations in my game. Basically (and I could be wrong about some of these details) if you’re working with the “Animator” component on a gameobject, you’re usually working with the new Mecanim animations system. If, on the other hand, your game object has an “Animation” component attached, you’re dealing with the legacy (older) animation system.
Usually to mark an animation as legacy, you must find your model/game object’s import settings on the .fbx file (or whatever the extension your model is) that you imported into Unity when you first imported the model. You just simply click on the .fbx (or whatever) file and it should bring up the import settings in the inspector with the “Model”, “Rig”, and “Animations” tabs.
But in your case it’s a little odd that you just have an animation alone, with no model it was attached to per-say. My guess is that you need to “skin” or “rig” your door properly, unless your using some sort of vertex animation…which in that case I don’t know much about that, sorry.
Did “animationtrail” show up in the console, as that was your message? Also, I’m going to assume you made the whole clip right. A good check would be to check the box “Play Automatically” in the Animation component so you can see how it looks or if it even works. You can also view the animation in the Animation window by clicking on the door in your hierarchy while having the Animation (not Animator) window open. The Animation window should show all the clips that are associated with this object at the moment- which should be your DoorOpen clip. You can also click the play button here to see how it looks.
Edit: Thanks for that info Velo!
Also… that makes me wonder. Is the DoorOpen clip even properly made, if it was made within Unity? Usually it’s made (as far as I can recall from doing animations within Unity) by clicking on the object you want to animate, clicking the Record button (after adding a property), adding keys, changing it at each key, etc… Basically, using the Animation window in conjunction with the object itself.