Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Ajizi · Dec 12, 2015 at 09:51 PM · scenetimerdifferent

Save timer score from different scenes

Im trying to build a game were the player should try and localize sound sources and then time them and save it. Then move on to the next scene and do the same thing but with a different sound. Right know I have a trigger on a gameobject which send the player to the next scene with :

Application.LoadLevel("level2");

But I cant seem to get a timer to work in the way that I want to. Can I get some help on what I should look for?

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 dhore · Dec 13, 2015 at 12:53 AM

So what you're trying to do is time the player, but keep adding on to that time across the different scenes rather than start again from 0, correct?

If so, you can just use a Static Variable which will stay the same across all scenes. See this question for an example.

EDIT: @Ajizi after your answer containing more info (not sure why you posted that as an answer though?) I now know exactly what you are looking for - just simply a way to make a timer. Well you're on the right track with Time.time; here's the code you need:

 // at start of game/round
 float startTime = Time.time;
 
 // when player finishes game/round
 float totalTime = Time.time - startTime;

As for saving to a text file, there's a nice explanation here.

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 Ajizi · Dec 13, 2015 at 12:54 PM 1
Share

Thanks man, time.time seems to be working out fine for my purpose. I ended up doing something like this:

 using UnityEngine;
 using System.Collections;
 using System.IO;
 
 
 
 public class Trigger : $$anonymous$$onoBehaviour {
 
     private float timer;
     
     void OnTriggerEnter(Collider sceneSwitch)
     {
         timer = Time.timeSinceLevelLoad;
         Debug.Log(timer);
 
         timer.ToString();
 
         StreamWriter dataTimer = new StreamWriter(@"C:\data.txt", true);
         dataTimer.WriteLine(timer);
         dataTimer.Close();
 
         Application.LoadLevel(Application.loadedLevel + 1);
     }
 }

It would be nice if the data.txt file was saved inside the same map as the .exe file though.

avatar image
0

Answer by Ajizi · Dec 13, 2015 at 10:24 AM

Im looking into time.time at the moment. I dont really need a visual timer. I need it to start when the game starts and stop it and save it to a file when the player finds the object. And then be able to do it again on a different scene with a different sound.

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

35 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

Related Questions

LoadScene() does not reload my GUI C# 2 Answers

Unity 5.1 networking 0 Answers

Post time at the end of the level 0 Answers

Countdown timer in multiple scene? 1 Answer

Gear VR template scene for Unity 5.1+ ? 0 Answers


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