Announcement

Collapse
No announcement yet.

Score Assistance

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Take a look at all the projects we've done up to now (space invaders to start with), and the code is there. You should be able to copy/paste it right out of that project.

    Remember to also take a look at the API.

    Comment


    • #17
      I found it in my notes. Do I put it in the score script, or the scorekeeper script?

      Comment


      • #18
        I am completely lost. I tried to put the player-refs into the scorekeeper script, but it isn't working.

        Comment


        • #19
          Playerprefs!!!

          Comment


          • #20
            Try and find where you implemented it in your project - not just your notes. I need you to do some of the work of figuring it out before coming to ask for the answer.

            You'll need playerprefs in two places. The first is where you set the playerprefs. This is likely on the script that knows when the game is over. So, wherever you're counting ammo would be a good place to set the playerprefs. Then, you'll need to get the playerprefs in the game over screen. That will likely be in a Start function and it can be on any object in the scene.

            Comment


            • #21
              In my case, the Shooter script is where I set the playerprefs. is it GetInt, or SetInt?

              Comment


              • #22
                Depends if you're trying to write the value (SetInt) or get a written value (GetInt). If it's on your shooter script, you probably need to use SetInt to write the value so you can retrieve it (GetInt) in the game over screen.

                Comment


                • #23
                  This is what I have so far. Is this correct? Click image for larger version

Name:	0318EFC1-F41E-4D54-A0E6-841CAF815A08.jpeg
Views:	10
Size:	335.3 KB
ID:	341023

                  Comment


                  • #24
                    Nope. You can see that it's not because it's highlighted in red. You need to get rid of the line:

                    Code:
                    public object SetInt {get; private set}

                    Comment


                    • #25
                      It was put into the code. Do I put the getint in the scorekeeper script?

                      Comment


                      • #26
                        So here's how PlayerPrefs work.

                        1) You set a value by using PlayerPrefs.SetInt("Name of Preference to Remember", valueToRemember);
                        __The shooter script is likely not the best place to put this line of code; because it doesn't know the score.
                        __If you put this line of code (instead) into the scorekeeper script, you could write to the player prefs every time you changed the score.
                        Code:
                        PlayerPrefs.SetInt("Score", score);
                        __You could also build another PlayerPrefs.SetInt to store the high score every time you changed the high score as well
                        Code:
                        PlayerPrefs.SetInt("HighScore", highScore);
                        2) Then in the gameOver level you read those values from the PlayerPrefs and write them to your UI. To read them you'd use
                        Code:
                        int score;
                        int highScore;
                        
                        void Start()
                        {
                             score = PlayerPrefs.GetInt("Score");
                             //Write to the score UI here
                             highScore = PlayerPrefs.GetInt("HighScore");  
                             //Write to the high score UI here
                        }

                        Comment


                        • #27
                          This is a troubleshooting problem. the UnityEngine.ui thing seems grayed out, and I get an error that says "Using directive is unnessecary".How can I fix this?

                          Comment


                          • #28
                            It's not
                            UnityEngine.ui
                            its
                            UnityEngine.UI;

                            Comment


                            • #29
                              That’s what I put into the visual studios, but it’s grated out and is deemed unnecessary.

                              Comment


                              • #30
                                Click image for larger version

Name:	Screen Shot 2020-03-25 at 9.20.38 PM.png
Views:	4
Size:	39.4 KB
ID:	341050Click image for larger version

Name:	Screen Shot 2020-03-25 at 9.20.49 PM.png
Views:	4
Size:	24.2 KB
ID:	341051 I am getting this error every time I try to input UnityEngine.UI

                                Comment

                                Working...
                                X