1
\$\begingroup\$

Ok so I added a play animation line to my trigger script. I made an animation, added it to the trigger object, attached the animation to the trigger, and tested. The target goes to the trigger as it should, deletes the trigger, but the animation never plays. So I check the console, and it's telling me "The AnimationClip 'MazeDoorClose' used by the Animation component 'SuckInTarget' must be marked as Legacy." so I do that, but now the trigger activates before the target gets there, and there is still no animation playing!

I know this sounds confusing so in an attempt to make it easier to understand I made a short video . Sorry for the crappy quality, but hey it's free. Here is the code:

using UnityEngine;
using System.Collections;

public class SuckIn : MonoBehaviour
{

    public Transform target;
    public float speed;
    public string ObjectWithTagToBeDestroyed;
    public string ThingToAnimate;

    void Update()
    {
        float step = speed * Time.deltaTime;
        target.position = Vector3.MoveTowards(target.position, transform.position, step);
    }

    void OnTriggerEnter(Collider coll)
    {
        if (coll.gameObject.tag == "Ball")
        {
            Destroy(GameObject.FindWithTag(ObjectWithTagToBeDestroyed));
            GetComponent<Animation>().Play(ThingToAnimate);
        }
    }

}

Before you ask yes the animation is on the object as it should be, and as Unity told me to do I marked it as a legacy animation. Any ideas what am doing wrong?

\$\endgroup\$
1
\$\begingroup\$

I'm not quite sure how to solve the legacy issue but I can recommend a different way to tackle your problem.

Instead of trying to play the animation directly use a parameter on the Animator Controller to trigger it. Here is a video released by Unity that trains you on creating them. This is very worth learning it is more robust and will give you greater control in the long run.

Regarding how to call it in your script, if you used a trigger (for a one time call) then you would type:

GetComponent<Animator>().SetTrigger("MyTriggerName");

Let me know if you have more questions on how to get this setup after watching the video/reading the documentation.

\$\endgroup\$
0
\$\begingroup\$

You have the animation to start as awake checked accidentally. Use the debug menu in the upper options panel in the inspector to see all the animation options.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.