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 /
avatar image
0
Question by bluesheepgamesofficial · Dec 27, 2017 at 08:44 PM · coroutineplayerprefsbooleanintinteger

Creating a Playerpref score system

I am brand new to Unity. Up to this point I have been using tutorials to help get my first game to where it is. I have looked through documentation, the forums and Youtube to find a beginning or solution to what I'm trying to do. What im attempting is a system where every second it gives you a set ammount of points. Every set ammount of points it gives you a coin. But everytime it updates you're points it updates the Score UI Text. I can't figure this out. I also can't figure out how to do a PlayerPref IF. Here is my code.

public Text scoreText; public Text highScoreText;

 public int pointsPerSecond;
 public int coinsPerPoints;
 public int score;
 public int matchCoins;

 // Use this for initialization
 void Start () {

     PlayerPrefs.GetInt("HighScore");
     score = 0;
     matchCoins = 0;
 

 }
 
 // Update is called once per frame
 void Update () {
     
 }

//THIS IS THE END OF CODE IN THIS FORUM POST

My idea is having an if that says if the Playerpref highscore is less then score after the bool "dead" Is activated in the player it updates the Highscore to be score. I know how to do that. But not how to access the Bool from my Player script. Or to set up Courotines or anything of the sort. And the Unity time system all around confuses me. Help here would be appreciated.

I also want to do where every 10 seconds it gives the player 5 coins. So all this goes over my head a bit.

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

Answer by Larry-Dietz · Dec 28, 2017 at 05:37 AM

Try something like this. It is untested, but I think it will do basically what you are wanting...

 public Text MyTextDisplay;
 public Player MyPlayer;
  public int pointsPerSecond;
  public int coinsPerPoints;
 private int _score; 
 public int score {
    get{return _score;}
    set {
       _score=value;
       MyTextDisplay.text = _score.ToString();
    }
 }
  public int matchCoins;
 private float PointTimer=0;
 private float CoinTimer=0;
 private bool GameOver=false;
 
  // Use this for initialization
  void Start () {
      score = 0;
      matchCoins = 0;    
  }
  
  // Update is called once per frame
  void Update () {
      if(GameOver)
          return;
 
      if (!MyPlayer.Dead) {
          PointTimer+=Time.deltaTime;
          if (PointTimer>1){
              PointTimer=0;
              Score+=pointsPerSecond;
          }
      CoinTimer+=Time.deltaTime;
          if (CoinTimer>10){
              CoinTimer=0;
              matchCoins+=5;
          }
      } else {
           int HighScore = PlayerPrefs.GetInt("HighScore",0);
           if (Score>HighScore)
               PlayerPrefs.SetInt("HighScore", Score);
      }
  }

Again, this is untested, I just wrote it here in the response directly, but short of a typo, I think it will do what you are looking for. Just drag the Player and Text objects into the appropriate fields in the inspector.

Hope this helps, -Larry

Comment
Add comment · Show 9 · 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 bluesheepgamesofficial · Dec 28, 2017 at 07:09 AM 0
Share

That worked well. Thanks alot man

avatar image Larry-Dietz bluesheepgamesofficial · Dec 28, 2017 at 07:24 AM 0
Share

You are welcome. Glad I could help. If you could, mark the answer as accepted :)

-Larry

avatar image bluesheepgamesofficial Larry-Dietz · Dec 28, 2017 at 07:26 AM 0
Share

I always forget to do that. Sorry

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

79 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Issue with PlayerPrefs not loading a value, as well as a bug... 1 Answer

PlayerPrefs setting to an existing int 0 Answers

Hello, I can I make a int for my coroutine that can check the value of the int every frame. 1 Answer

How to stop a boolean from going back to false 1 Answer

make events occur only at specific times 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