Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
0
Question by kbeaud · Feb 13, 2013 at 05:26 PM · animationcameramovementscenes

End of Animation

Hello, I have this animation right, and when it finishes I want it to load a scene. So for example I have my camera... when a certain button is clicked, the camera moves behind the wall where you only see black. Now when the animation on the camera finishes I would like it to send me to, for example "Scene X".

Thanks!

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by dannyskim · Feb 13, 2013 at 05:31 PM

Here are some animation extensions that I wrote for a project to do basically what you're asking, as well as things as callbacks for OnUpdate, a delay before the animation is played, etc.

 using UnityEngine;
 using System;
 using System.Collections;
 
 /* Animation Extensions, Written by DSK
  * 
  * Used to extend functionality of the Unity Animation Class by way of CoRoutine
  * 
  */
 public static class AnimationExtensions {
     
     public static IEnumerator PlayWithOptions(this Animation animation, string animName, Action onComplete)
     {
         animation.Play(animName);
 
         while (animation.isPlaying) { yield return null; }
 
         onComplete();
     }
 
     public static IEnumerator PlayWithOptions(this Animation animation, string animName, float delay, Action onComplete)
     {
         yield return new WaitForSeconds(delay);
 
         animation.Play(animName);
 
         while (animation.isPlaying) { yield return null; }
 
         onComplete();
     }
 
     public static IEnumerator PlayWithOptions(this Animation animation, string animName, Action onUpdate, Action onComplete)
     {
         animation.Play(animName);
 
         while (animation.isPlaying)
         {
             onUpdate();
             yield return null;
         }
 
         onComplete();
     }
 
     public static IEnumerator PlayWithOptions(this Animation animation, string animName, float delay, Action onUpdate, Action onComplete)
     {
         yield return new WaitForSeconds(delay);
 
         animation.Play(animName);
 
         while (animation.isPlaying)
         {
             onUpdate();
             yield return null;
         }
 
         onComplete();
     }
 }

These functions are extending the Unity Animation class. For use, you would do something like:

 StartCoroutine( gameObject.animation.PlayWithOptions( 
                 animToPlay,
                 () => 
                 { 
                     Debug.Log( "ANIMATION FINISHED, LOADING SCENE X" );
                                     Application.LoadLevel( "SceneX" );
                 }
                 )
             );
Comment
Add comment · Show 6 · 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 kbeaud · Feb 13, 2013 at 06:15 PM 0
Share

So the second one does what I need?

avatar image $$anonymous$$ · Feb 13, 2013 at 06:36 PM 0
Share

the whole thing does what you need... of course if you copy-paste it, you probably won't understand why it works. btw nice script

avatar image dannyskim · Feb 13, 2013 at 06:55 PM 0
Share

Yes, the second one does what you need, but you need the first one to accomplish it. Copy and paste the first code section and save it as a C# script in your project, then you'll be able to call the code as depicted in the second code section.

@z_murc, thanks for the kind comments.

avatar image kbeaud · Feb 13, 2013 at 10:06 PM 0
Share

The animation I'm calling it fade_into_black should go into the animname?

avatar image kbeaud · Feb 13, 2013 at 10:12 PM 0
Share

and does anything need to go in onComplete();?

Show more comments

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.

Follow this Question

Answers Answers and Comments

10 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Play animation for horizontal and vertical movement? 1 Answer

How to run an animation mouse click. 2 Answers

Stop Movement while attacking 2 Answers

Smooth transition from Camera1 to Camera2? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges