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 Kanza · Dec 15, 2011 at 06:06 PM · animationraycaststartcoroutineapplication.loadlevelelevator

Elevator to load next scene

Hey guys, I'm having a big problem with my script. It does all what I want it to do until I put a yield on it so that it waits for the animation to finish before it loads the new scene; instead it plays no animation and just goes straight to a new scene. Script:

 function Update () 
 {
 var hit :RaycastHit;
 if (Physics.Raycast(transform.position, transform.forward, hit, 5))
 {
 if(hit.collider.gameObject.tag == "Elevator")
 {
 if(Input.GetKeyDown(KeyCode.I))
 {
  hit.collider.gameObject.animation.Play("Elevator");
  StartCoroutine();
  Startagain();
 }
 }
 }
 }
 function StartCoroutine (){
 animation.Play(animation.clip.name);
 yield WaitForSeconds (animation.clip.length + 2);
 }
 function Startagain (){
 Application.LoadLevel(1);
 }
 
  

  

Thanks for your help Kanza

Comment
Add comment · Show 4
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 gregzo · Dec 15, 2011 at 06:41 PM 0
Share

Your script has a few mistakes. I'll be glad to help if you format it properly first.

avatar image Kanza · Dec 15, 2011 at 07:10 PM 0
Share

Hey man thanks for that, works perfectly now! I have a code which is working also but I'm unsure of many things, is there anyway I can contact you outside of here?

Thanks $$anonymous$$anza.

avatar image gregzo · Dec 15, 2011 at 07:10 PM 0
Share

@$$anonymous$$arkFinn +1 for reading unformatted code. @$$anonymous$$anza Following the conventions actualy help a lot, I promise you.

avatar image Kanza · Dec 15, 2011 at 07:12 PM 0
Share

Well this is my first time scripting and I'm bad at it soooo yeah sorry for it not being formatted.

2 Replies

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

Answer by MarkFinn · Dec 15, 2011 at 09:40 PM

MOve the call to StartAgain() inside the coroutine, after the yield.

That is,

 

function Update () 
{
var hit :RaycastHit;
if (Physics.Raycast(transform.position, transform.forward, hit, 5))
{
if(hit.collider.gameObject.tag == "Elevator")
{
if(Input.GetKeyDown(KeyCode.I))
{
 hit.collider.gameObject.animation.Play("Elevator");
 StartCoroutine();

                  
                   Startagain();
                  
}
}
}
}
function StartCoroutine (){
animation.Play(animation.clip.name);
yield WaitForSeconds (animation.clip.length + 2);
 Startagain();
}
function Startagain (){
Application.LoadLevel(1);
}

Comment
Add comment · Show 1 · 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 Kanza · Dec 15, 2011 at 09:47 PM 0
Share

Yeah thanks works just dandy, now ima add a sound clip to it :P

avatar image
2

Answer by MarkFinn · Dec 15, 2011 at 06:52 PM

As the system refuses to display my fully typed out answer, please accept this short form instead:

Simply move the call "Startagain();" inside the "StartCoroutine();", after the line "yield WaitForSeconds (animation.clip.length + 2);".

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.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Error in Raycast Detect Ground for Falling Animation 1 Answer

Animation Event calling function 1 Answer

Best / easiest way to play an animation after getting hit by a raycast 1 Answer

Stop animation when no more bullets 1 Answer

Enemy Animation to not stop when player runs out of range 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