Animating and throwing and object at the same time

Nothing is simple in here.

Developing my game I need that an Enemy throws objects every 10 seconds, for instance, against my Player. Just at the same times the Enemy should mimic with an animation clip (1 second long) the repetitive throws. I have done it all, except the script piece that could allow me make the task. I wrote a very simple line script nested in my Up Date function:

animation["Take 001"].speed = 2.0;

where "Take 001" is my animation clip and 2.0 is the speed of the animation.

This made the job, but ONLY ON THE FIRST TROW. From there on only the objects are thrown but without the animations.

Any help on this LITTLE issue! (nothing is little in this field)

Could you post some more code?

3 Answers

3

Add the line

animation.Play("Take 001");

to your code that throws the objects.

If that doesn't help post us some more code and we can take a better look.

You could check the Wrap Mode (and set it to "loop"):

animation.wrapMode = WrapMode.Loop;

Therefore, none of them is the solution. I would appreciate any further advice.

Summarizing, what I want is one animation loop every 10 seconds.

Take a look at InvokeRepeating http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.InvokeRepeating.html

I wrote down this line: InvokeRepeating (animation["Take 001"], 0, 10); but I got this error: Assets/Scripts/MonkeyAnimation.js(20,17): BCE0017: The best overload for the method 'UnityEngine.MonoBehaviour.InvokeRepeating(String, float, float)' is not compatible with the argument list '(UnityEngine.AnimationState, int, int)'. Any further advice, please?

Here is how I resolved my problem. My animation was done in Maya, therefore I made in Maya a new animation (as my animation is very simple I only invested on it five to ten minutes) with 1 second duration and 9 seconds without movement in order to fill the 10 seconds I needed. For this I compared time an frame-times with the Unity Animator (Window > Animation, with the Character selected). I imported again to Unity the Character with the new timing and wrote the line: animation.Play("Take 001"); nested in the Up Date function in the Character script and I got the animation that I wanted synchronized with the objects launched. I am sure there are many other ways to fix the problem, but this worked very good for me.

By the way, the imported animations from Maya, at least on my case, are not editable because they produce the message Read Only in the Unity Animator.

SOLVED!