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
1
Question by basketballrox103 · Apr 13, 2011 at 12:59 AM · timeplayerprefsloadinglevel

Storing in PlayerPref based on timer

Officially first post on here so take it easy on me. I'm using a js to countdown (using 2 minutes). What I need is to store a 3 (for 3 stars) if they get it done in 1:40-1:50. Store a 2 (for 2 stars) if they get done in 1:50 to 2:00. And store a 1 (for 1 star) if they finish after 2:00. I would then use this value after the next level to display how many stars. I would also use this to unlock a secret level if 3 stars were acheived on all 5 levels. Code for Timer:

var startTime: float; var timeRemaining:float; function Start(){ startTime = 120.0; guiText.material.color = Color.red; } function Update () { Countdown(); } function Countdown(){ timeRemaining = startTime - Time.time; ShowTime(); if(timeRemaining < 0) { timeRemaining = 0; TimeIsUp();

   Debug.Log("Time remaining = "+ timeRemaining);
 }

} function ShowTime(){ var minutes: int; var seconds: int; var timeString : String; minutes = timeRemaining/60; seconds = timeRemaining%60; timeString = minutes.ToString() +":" + seconds.ToString("D2"); guiText.text = timeString; } function TimeIsUp(){ Debug.Log("Time is up!"); }

Right now this works and displays "Time is up!" but I'm wanting it to store those values instead. I'm assuming using PlayerPrefs would be the best way. I also would like a way for my box collider to store a true value in PlayerPrefs so that I could use it for my level unlock screen. Any help is appriciated and I can post more code or info about my game if needed. Thanks

Comment
Add comment · Show 1
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 Justin Warner · Apr 13, 2011 at 01:38 AM 0
Share

Great first ? but you didn't format your code =P No biggie though, great job, again! =)

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Justin Warner · Apr 13, 2011 at 01:59 AM

Ok, by not having what the game is, I'll go with what I can.

On the condition that the player HAS finished the game/level, run a function (Done), and pass through the timeRemaining.

Ok, by not having what the game is, I'll go with what I can.

On the condition that the player HAS finished the game/level, run a function (Done), and pass through the timeRemaining.

function Done(float time){
    if(time <= 110.0)
    {
      PlayerPrefs.SetFloat("Player Stars", PlayerPrefs.GetFloat("Player Stars")+3);
    }
    else if(time <=  120&& time >= 110)
    {
      PlayerPrefs.SetFloat("Player Stars", PlayerPrefs.GetFloat("Player Stars")+2);
    }
    else if(time > 120)
    {
      PlayerPrefs.SetFloat("Player Stars", PlayerPrefs.GetFloat("Player Stars")+1);
    }
}

If you have any questions, ask... But this should make sense.... Hope it helped!

Comment
Add comment · Show 2 · 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 basketballrox103 · Apr 13, 2011 at 03:30 AM 0
Share

Ok everything makes sense but I have never used PlayerPrefs. So basically this calls the Player Stars and adds either 1, 2, or 3. Then when I access it in my completed level or complete game scenes I use PlayerPrefs.GetFloat("Player Stars"). I'm assu$$anonymous$$g player prefs can be accessed in any scene..? Also any links to using PlayerPrefs to unlock levels? And thanks that helps a ton!

avatar image Justin Warner · Apr 13, 2011 at 12:16 PM 0
Share

For the unlock levels, you just do if(PlayerPrefs.GetFloat("Player Stars" ) >= 10) { //GUI STUFF ] It's really easy... And yes, you have that right =)

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

No one has followed this question yet.

Related Questions

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

PlayerPrefs Question 0 Answers

Seamless Room Transitions 0 Answers

How do you save timer with PlayerPrefs? 1 Answer

Help With Quickest TimeScore 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