• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by CupOfMayo · Oct 01, 2016 at 07:35 PM · animationanimatortimechange

Jump to specyfic time/frame in current animation using animator?

Hey so pretty much I have one variable with time or frame. Let's say that my current animation is at time = 0 and after button is pressed it changes to time given in variable. How can it be achieved?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by CupOfMayo · Oct 02, 2016 at 12:21 PM

Searching thru the web I actually figured it out by connecting few ideas :)

     Animator anim;
     public float normalizedTime = 0;
     // Use this for initialization
 
     void Start () {
         anim = gameObject.GetComponent<Animator> ();
     }
     
     // Update is called once per frame
     void Update () {
         if (Input.GetKeyDown (KeyCode.Q)) {
             jumpToTime (currentAnimationName (), normalizedTime);
         }
     }
 
     void jumpToTime(string name, float nTime)
     {
         anim.Play (name, 0, nTime);
     }
 
     string currentAnimationName()
     {
         var currAnimName = "";
         foreach (AnimationClip clip in anim.runtimeAnimatorController.animationClips) {
             if (anim.GetCurrentAnimatorStateInfo (0).IsName (clip.name)) {
                 currAnimName = clip.name.ToString();
             }
         }
 
         return currAnimName;
 
     }
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Enumerator_T · Jan 21, 2018 at 08:22 PM

@CupOfMayo

Using events in the animation window allows me to check if the animation is playing by setting an animation event at the very start of the animation and triggering 'IntroPlaying' on the event its self to trigger the button state on the GUI.

 public bool IntroStarted;
   public void IntroPlaying()
   {
     IntroStarted = true;
   }

If the Animation has started, display the button and set the time of the animation state called "RoomEnter" then set "IntroStarted" to false

  public Camera Cam;
  public Animator anim;
 
   private void OnGUI()
   {
     if (IntroStarted)
     {
       if (GUI.Button(new Rect(Screen.width / 2 - 50, 10, 100, 50), "Skip"))
       {
         anim = Cam.gameObject.GetComponent<Animator>();
         anim.Play("RoomEnter", 0, 10.0f);
         IntroStarted = false;
       }
     }
   }

Cam is the MainCamera Game Object which you will have to set either programatically or using public Camera Cam; Hope this helps.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

120 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I set the time of an animation playing in the animator (Mechanum) 5 Answers

Animate only after certain time 1 Answer

Chande animation speed 1 Answer

Animator idle minimal delay 0 Answers

normalized time always greater than 1 on non-looped animations. 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges