0
\$\begingroup\$

I want to enable a canvas while an animation clip is playing, I used animation Event and call the following script to enable the canvas, but the editor does not recognize any game object.

How a canvas can be enabled?

public void SetActiveTrue(GameObject game_object)
{
    game_object.SetActive(true);
}
\$\endgroup\$
1
\$\begingroup\$

This is a conceptual problem, Animations are file assets in the project while GameObject is a reference to something in your active Scene(s). you cannot drag a Scene GameObject in an AnimationEvent but only prefabs. you can have a workaround:

  • by passing a string and doing the lookup ? don't forget some defensive null checks.
  • Having that animation directly in a parent of the Canvas so you can enable it directly in the timeline ?
\$\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.