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 stve101 · Apr 02, 2012 at 05:26 PM · timeloadlevel

Different scene depending on level completion time remaining?

Hi guys,

I'm trying to incorporate a function where a player must reach an area within a particular time limit. I've got my timer script set up so when it reaches zero, a 'gameover' scene is loaded:

 var startTime = 90.0;
 
 var timeLeft : int;
 
 
 function Update () {
     
     //Time left
     
     timeLeft = startTime - Time.time;
     timeLeft = Mathf.Max (0, timeLeft);
     guiText.text = FormatTime (timeLeft);
     
     if (timeLeft == 0) {
         print ("Time is up!");
         Application.LoadLevel("gameover");
     }
     }

Now I'm trying to figure out how i can add a function so when the 'player' collides with the 'portal' with say, 20 seconds left to spare, a scene indicating that they'd won a 'gold medal' would load up. If they instead happened to finish with 10 seconds left to spare, then a different scene would load up indicating that they had won a 'silver medal' etc. Overall, I'm aiming to produce three different end-of-level scenes (Gold, Silver, Bronze).

I have a script attached to the 'portal' gameobject which currently identifies if the 'player' collides with it, to then apply a Application.LoadLevel function. Of course, with this new function I am trying to implement, I'm assuming i would need to pass some kind of if statement through? This is the script after various attempts of getting the newly proposed function to work:

    var timeLeft : int;
 
 function OnCollisionEnter (theCollision : Collision) {
     
     if(theCollision.gameObject.name == "player"){
         (timeLeft > 20) {
             print ("Gold!");
             Application.LoadLevel("gold-medal-scene");
         }
     }
     }
 

  //if (timeLeft > 10) {
             //print ("Silver!");
             //Application.LoadLevel("silver-medal-scene");

The commented out section is what I am assuming is the way I would get the function to work, but the problem i have is that I already have an if statement applied to the OnCollisionEnter script to identify the collection detection. :/

So I'm writing to ask for your advice and help as to how I could pass this proposed function within the script that I have. Any guidance would be greatly appreciated!

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
3
Best Answer

Answer by BiG · Apr 02, 2012 at 05:31 PM

You can use if-statements enclosed into other ones. I would modify your script as follows, assuming that you win a gold medal for 20+ secs, a silver one for 10+ secs, and a bronze one for finishing the level with less than 10 secs.

 var timeLeft : int;
 
 function OnCollisionEnter (theCollision : Collision) {
 
     if(theCollision.gameObject.name == "player"){
        if (timeLeft > 20) {
           print ("Gold!");
           Application.LoadLevel("gold-medal-scene");
        }
        else if (timeleft > 10){
           print ("Silver!");
           Application.LoadLevel("silver-medal-scene");
        }
        else if (timeleft > 0){
           print ("Bronze!");
           Application.LoadLevel("bronze-medal-scene");
        }    
    }
 }
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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

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

Delaying through yield 2 Answers

How to write a simple save script 1 Answer

Loadlevel when you press a key? 3 Answers

pause timer or player using Time.timeScale 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