0
\$\begingroup\$

I want to do the same as this older post with one change:

Change the sprite of a Object in Unity

I want to use a .anim animation (created with unity) after the space key is pressed instead of another sprite. The problem is I can't drag the animation file to the sprite slot in the script component.

Thanks.

\$\endgroup\$
  • \$\begingroup\$ What is your desired effect? Are you just looking to transition from one animation to another? \$\endgroup\$ – Savlon Jul 20 '15 at 23:16
  • \$\begingroup\$ It's a cooking game, I get to the point where I go near to the stove, press space and it shows a debug message I made. Now I need to change the sprite to an animated stove with fire instead of the debug message and then reverse it by pressing space again. \$\endgroup\$ – d4ni3lb Jul 22 '15 at 1:42
  • \$\begingroup\$ I would use the animator and change states to transition to different animations... Make your default animation contain one image (unlit stove) then when you press space bar, change state to transition to lit stove image sequence. This is basic stuff and not unique to you... Look at a basic animation tutorial on YouTube, there are plenty. \$\endgroup\$ – Savlon Jul 22 '15 at 6:57
2
\$\begingroup\$

You do not have to drag drop animation controller to your script instead you can add component to game object using inspector. Add an Animator component first.

On your required key press you have two possibilities as i see:

  1. Enable/disable the component as per your need.
  2. If you want to run two different states you can use states based animations. Steady State, Running State.

Recommended Read:

Hope it helps!

\$\endgroup\$
  • \$\begingroup\$ Thanks!! I was looking for how to use the animator sice I saw some pictures of it but never found out how. \$\endgroup\$ – d4ni3lb Jul 26 '15 at 14:47

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.