C
C#ā€¢2y ago
SteliosKrom

āœ… How to Save HighScore in each difficulty separately?

I don't know how to save players HighScore for each difficulty separately, so that it will not be the same HighScore for every difficulty.
885 Replies
JakenVeina
JakenVeinaā€¢2y ago
well, first you would have separate difficulties then you would save a player's HighScore separately for each one
SteliosKrom
SteliosKromOPā€¢2y ago
I will send you right now code I did that, I have separate difficulties I don't know how to save the highscore whenever I click to each difficulty and play I did something like
if (gameobject.comparetag("EasyButton") then do {
}
if (gameobject.comparetag("EasyButton") then do {
}
TheRanger
TheRangerā€¢2y ago
use playerPrefs like you used before?
PlayerPrefs.SetInt("HighScore_Easy", score); // for easy
PlayerPrefs.SetInt("HighScore_Medium", score); // for medium
PlayerPrefs.SetInt("HighScore_Hard", score); // for hard
PlayerPrefs.SetInt("HighScore_Easy", score); // for easy
PlayerPrefs.SetInt("HighScore_Medium", score); // for medium
PlayerPrefs.SetInt("HighScore_Hard", score); // for hard
SteliosKrom
SteliosKromOPā€¢2y ago
Yes but I have buttons I click on each difficulty I don't want to make more high scores One high score for each Wait I think I have an idea I have a difficulty script and in this script I have a button.addlistener So in this script st the start() method I have to make all that to happen Maybe I can use tags For each button and then compare them And do my work
TheRanger
TheRangerā€¢2y ago
u said u want to save highscore for each difficulty right?
SteliosKrom
SteliosKromOPā€¢2y ago
If (it is easy and isclikced) then do playerprefs Else if () do again the same stuff Yes that what I want That's
TheRanger
TheRangerā€¢2y ago
this was just a representation on how to save for each difficulty you take each line for each button
SteliosKrom
SteliosKromOPā€¢2y ago
Yes I don't want three high scores to have
TheRanger
TheRangerā€¢2y ago
if (easy) then PlayerPrefs.SetInt("HighScore_Easy", score); // for easy
SteliosKrom
SteliosKromOPā€¢2y ago
Oh wait The high score will be the first one I made right?
TheRanger
TheRangerā€¢2y ago
if (gameobject.comparetag("EasyButton") then do {
PlayerPrefs.SetInt("HighScore_Easy", score); // for easy
}
if (gameobject.comparetag("EasyButton") then do {
PlayerPrefs.SetInt("HighScore_Easy", score); // for easy
}
SteliosKrom
SteliosKromOPā€¢2y ago
So I have to make three variables For high score for each difficulty
TheRanger
TheRangerā€¢2y ago
3 variables of what?
SteliosKrom
SteliosKromOPā€¢2y ago
Highscore_easy and all of that Or I am confused
TheRanger
TheRangerā€¢2y ago
you just need 1 variable of score to display on screen
SteliosKrom
SteliosKromOPā€¢2y ago
Yes and the other for high score Why you used three strings in playerptefs Prefa
TheRanger
TheRangerā€¢2y ago
u also need 1 variable of high score to display on screen
SteliosKrom
SteliosKromOPā€¢2y ago
Prefs
TheRanger
TheRangerā€¢2y ago
depending on what difficulty u chose, u load the high score from playerPrefs then assign it to the high score variable that u need to display on screen
SteliosKrom
SteliosKromOPā€¢2y ago
Yes but I didn't understand what those three strings do inside of player prefs?
TheRanger
TheRangerā€¢2y ago
No need to load the rest of the high scores that you wont display theyre just data stored in your pc and playerprefs load or save them to ur pc
SteliosKrom
SteliosKromOPā€¢2y ago
So, they don't actually do something right?
TheRanger
TheRangerā€¢2y ago
if they dont then Unity wouldnt have created this class
SteliosKrom
SteliosKromOPā€¢2y ago
I still can't understand bro how we use player prefs. Like what's the difference between playerprefs.getint and set int
TheRanger
TheRangerā€¢2y ago
GetInt gets the specified data from ur pc as Integer
SteliosKrom
SteliosKromOPā€¢2y ago
Playerptefs("High score", score) it store the score to high score string
TheRanger
TheRangerā€¢2y ago
SetInt saves the specified data into ur pc
SteliosKrom
SteliosKromOPā€¢2y ago
Ok Which here the specified data is the score?
TheRanger
TheRangerā€¢2y ago
u specify it
SteliosKrom
SteliosKromOPā€¢2y ago
Yes so this is the specified?
TheRanger
TheRangerā€¢2y ago
which one?
SteliosKrom
SteliosKromOPā€¢2y ago
The score In played prefs Player prefs
TheRanger
TheRangerā€¢2y ago
current score or high score?
SteliosKrom
SteliosKromOPā€¢2y ago
Current
TheRanger
TheRangerā€¢2y ago
PlayerPrefs.SetInt("HighScore_Easy", current_score);
SteliosKrom
SteliosKromOPā€¢2y ago
I save the score that I checked before and pass it to the high score something like that isn't it ?
TheRanger
TheRangerā€¢2y ago
saves ur current score into ur pc in HighScore_Easy say ur current_score was 12345 and u called this method next time u do current_score = PlayerPrefs.SetInt("HighScore_Easy"); whether u restarted the game or not it will store 12345 into current_score
SteliosKrom
SteliosKromOPā€¢2y ago
Ok that's understood but I don't want that I want it to be stored on high score Not in the current score
TheRanger
TheRangerā€¢2y ago
choose ur variable then
SteliosKrom
SteliosKromOPā€¢2y ago
Oh ok Coming in 1 hour back I have some work to do thanks! Hey, I am back I did what you said
SteliosKrom
SteliosKromOPā€¢2y ago
SteliosKrom
SteliosKromOPā€¢2y ago
I made this method and I call it to startgame method
SteliosKrom
SteliosKromOPā€¢2y ago
SteliosKrom
SteliosKromOPā€¢2y ago
I call it in that But I am not sure if it is correct I don't see anything to happen This is in game manager I will send the code in difficulty script
TheRanger
TheRangerā€¢2y ago
ur trying to load from HighScore without specifing the one with a difficulty
SteliosKrom
SteliosKromOPā€¢2y ago
Maybe I have to add more parameters for each button I don't think so but check the other code
SteliosKrom
SteliosKromOPā€¢2y ago
SteliosKrom
SteliosKromOPā€¢2y ago
Thats in difficulty script
TheRanger
TheRangerā€¢2y ago
does that compile?
SteliosKrom
SteliosKromOPā€¢2y ago
What do you mean compile?
TheRanger
TheRangerā€¢2y ago
like, can u run the game without any errors?
SteliosKrom
SteliosKromOPā€¢2y ago
Yes The game has no errors
TheRanger
TheRangerā€¢2y ago
what do the values of difficulty represent? 0 for easy, 1 for medium, 2 for hard?
SteliosKrom
SteliosKromOPā€¢2y ago
The actualy problem I have is how to save my highscore on start for each difficulty and on game over i want it to be saved for another try if the player want to try it again The game has a restart So, I reload the scene back to menu
TheRanger
TheRangerā€¢2y ago
?
SteliosKrom
SteliosKromOPā€¢2y ago
The values of difficulty represent the spawn rate speed So what I did was that spawnRate /= difficulty;
TheRanger
TheRangerā€¢2y ago
so how would the game know if ur on easy, medium or hard?
SteliosKrom
SteliosKromOPā€¢2y ago
Because I add a listener Check the code above here
TheRanger
TheRangerā€¢2y ago
so u know based on the spawn rate speed?
SteliosKrom
SteliosKromOPā€¢2y ago
Maybe I have to compare tags in set difficulty method? yes
TheRanger
TheRangerā€¢2y ago
thats not a professional way to do it use an Enum
SteliosKrom
SteliosKromOPā€¢2y ago
I am not a professional XD I am just a beginner enum? how to use it?
TheRanger
TheRangerā€¢2y ago
Enumeration types - C# reference
Learn about C# enumeration types that represent a choice or a combination of choices
SteliosKrom
SteliosKromOPā€¢2y ago
Can you show me how to make it happen?
TheRanger
TheRangerā€¢2y ago
in ur case u define it like
public enum Difficulty
{
Easy,
Medium,
Hard
}
public enum Difficulty
{
Easy,
Medium,
Hard
}
SteliosKrom
SteliosKromOPā€¢2y ago
Oh, ok.
TheRanger
TheRangerā€¢2y ago
enum is a type, like classes
SteliosKrom
SteliosKromOPā€¢2y ago
Alright
TheRanger
TheRangerā€¢2y ago
u can define it in its own file
SteliosKrom
SteliosKromOPā€¢2y ago
So, that will be in game manager right? After that what are the next steps?
TheRanger
TheRangerā€¢2y ago
define it in its own file
SteliosKrom
SteliosKromOPā€¢2y ago
I did it.
TheRanger
TheRangerā€¢2y ago
ok create a field for it in the game manager
public Difficulty difficulty;
public Difficulty difficulty;
SteliosKrom
SteliosKromOPā€¢2y ago
oh, ok
TheRanger
TheRangerā€¢2y ago
the default value will be Easy since its the first one defined in the enum for which button is that on the first image?
SteliosKrom
SteliosKromOPā€¢2y ago
It is for each of them like for easy, medium and hard you mean that ?
TheRanger
TheRangerā€¢2y ago
no, that can u show the full class of that image?
SteliosKrom
SteliosKromOPā€¢2y ago
yes I will take 2 screenshots cuz it is big
TheRanger
TheRangerā€¢2y ago
u can just use $code
MODiX
MODiXā€¢2y ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat If your code is too long, post it to: https://paste.mod.gg/
SteliosKrom
SteliosKromOPā€¢2y ago
oh yes Can you give me an example of how to do it ? oh understood How to share it I saved it in blazebin ?
TheRanger
TheRangerā€¢2y ago
copy paste the link
SteliosKrom
SteliosKromOPā€¢2y ago
BlazeBin - pgglgggzsruv
A tool for sharing your source code with the world!
TheRanger
TheRangerā€¢2y ago
huh i dont see this code on the first image
SteliosKrom
SteliosKromOPā€¢2y ago
I just delete it I thought was unuseful I can write it again
TheRanger
TheRangerā€¢2y ago
do u want to write it again?
SteliosKrom
SteliosKromOPā€¢2y ago
Ok Do i have to write it again?
TheRanger
TheRangerā€¢2y ago
you have 3 buttons to set difficulty right?
SteliosKrom
SteliosKromOPā€¢2y ago
I will use it somewhere? Yes
TheRanger
TheRangerā€¢2y ago
how will the buttons know which difficulty to set?
SteliosKrom
SteliosKromOPā€¢2y ago
Oh yes so i have to compare tags
TheRanger
TheRangerā€¢2y ago
compare tags where?
SteliosKrom
SteliosKromOPā€¢2y ago
In game manager Wait the first image you mean this ? Thats in another script I have it
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class DifficultyButton : MonoBehaviour
{

public float difficulty;
public bool isClicked = false;

private Button button;
private GameManager gameManager;

// Start is called before the first frame update
void Start()
{
button = GetComponent<Button>();
gameManager = GameObject.Find("GameManager").GetComponent<GameManager>();
button.onClick.AddListener(SetDifficulty);
}

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

}

void SetDifficulty()
{
Debug.Log(button.gameObject.name + " was clicked");
gameManager.StartGame(difficulty);
}

}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class DifficultyButton : MonoBehaviour
{

public float difficulty;
public bool isClicked = false;

private Button button;
private GameManager gameManager;

// Start is called before the first frame update
void Start()
{
button = GetComponent<Button>();
gameManager = GameObject.Find("GameManager").GetComponent<GameManager>();
button.onClick.AddListener(SetDifficulty);
}

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

}

void SetDifficulty()
{
Debug.Log(button.gameObject.name + " was clicked");
gameManager.StartGame(difficulty);
}

}
Thats the diffuclty script ? I don't know but I think i have to make a method in which I will compare tags that will be the buttons and the I will save with prefs and also to call it in start game. I confused a little bit with that
TheRanger
TheRangerā€¢2y ago
ok so u attached this script to each button right?
SteliosKrom
SteliosKromOPā€¢2y ago
yes
TheRanger
TheRangerā€¢2y ago
i guess that works,
SteliosKrom
SteliosKromOPā€¢2y ago
What I said?
TheRanger
TheRangerā€¢2y ago
change public float difficulty;
SteliosKrom
SteliosKromOPā€¢2y ago
I have it float
TheRanger
TheRangerā€¢2y ago
to public Difficulty difficulty;
SteliosKrom
SteliosKromOPā€¢2y ago
oh ok
TheRanger
TheRangerā€¢2y ago
and set Easy, Medium,Hard for each button in their inspector window
SteliosKrom
SteliosKromOPā€¢2y ago
I cant set it difficulty difficulty In the other script
TheRanger
TheRangerā€¢2y ago
what do u mean?
SteliosKrom
SteliosKromOPā€¢2y ago
IT says that
TheRanger
TheRangerā€¢2y ago
show screenshot?
SteliosKrom
SteliosKromOPā€¢2y ago
SteliosKrom
SteliosKromOPā€¢2y ago
Only difficulty button
TheRanger
TheRangerā€¢2y ago
where did u define the enum?
SteliosKrom
SteliosKromOPā€¢2y ago
In gamemanager
TheRanger
TheRangerā€¢2y ago
makes sense it cant find it
SteliosKrom
SteliosKromOPā€¢2y ago
gamemanager.difficutly maybe
TheRanger
TheRangerā€¢2y ago
i told you define it in its own file
SteliosKrom
SteliosKromOPā€¢2y ago
public GameManager.difficulty difficulty; I did that it is correct no errors
TheRanger
TheRangerā€¢2y ago
thats just ugly and not recommended
SteliosKrom
SteliosKromOPā€¢2y ago
ok
TheRanger
TheRangerā€¢2y ago
+ C# naming conventions recommend u to name Enum with PascalCase Difficulty not difficulty and camelCase for fields difficulty
SteliosKrom
SteliosKromOPā€¢2y ago
so enum difficulty
TheRanger
TheRangerā€¢2y ago
what? change
public enum difficulty
{
easy,
medium,
hard
}
public enum difficulty
{
easy,
medium,
hard
}
to
public enum Difficulty
{
Easy,
Medium,
Hard
}
public enum Difficulty
{
Easy,
Medium,
Hard
}
the bottom is the recommended way
SteliosKrom
SteliosKromOPā€¢2y ago
oh ok I did the first one
TheRanger
TheRangerā€¢2y ago
dont do what i didnt write
SteliosKrom
SteliosKromOPā€¢2y ago
Now it works I just have it the same as the parameter Thats why I change it I do what you say šŸ™‚
TheRanger
TheRangerā€¢2y ago
what parameter?
SteliosKrom
SteliosKromOPā€¢2y ago
I just have it the same with the parameter in start game Now i have a problem
TheRanger
TheRangerā€¢2y ago
i have no idea what parameter ur talking about
SteliosKrom
SteliosKromOPā€¢2y ago
Check that in difficulty script
SteliosKrom
SteliosKromOPā€¢2y ago
TheRanger
TheRangerā€¢2y ago
yeah
SteliosKrom
SteliosKromOPā€¢2y ago
This parameter
TheRanger
TheRangerā€¢2y ago
ud need to change the parameter type of StartGame its float, change it to the enum public void StartGame(Difficulty difficulty)
SteliosKrom
SteliosKromOPā€¢2y ago
oh ok Now I ve got some problems i did that you said
SteliosKrom
SteliosKromOPā€¢2y ago
SteliosKrom
SteliosKromOPā€¢2y ago
Why that happens? I did what you said it got me some errors here
TheRanger
TheRangerā€¢2y ago
lets start with the first line
SteliosKrom
SteliosKromOPā€¢2y ago
Ok
TheRanger
TheRangerā€¢2y ago
go to the line where the first error is
SteliosKrom
SteliosKromOPā€¢2y ago
SteliosKrom
SteliosKromOPā€¢2y ago
Here it is
TheRanger
TheRangerā€¢2y ago
there is a lonely public on line 8 have i ever told u that?
SteliosKrom
SteliosKromOPā€¢2y ago
I just removed it
TheRanger
TheRangerā€¢2y ago
ok
SteliosKrom
SteliosKromOPā€¢2y ago
XD
TheRanger
TheRangerā€¢2y ago
next error
SteliosKrom
SteliosKromOPā€¢2y ago
SteliosKrom
SteliosKromOPā€¢2y ago
Here is the next Because I cant in start game method divide that
TheRanger
TheRangerā€¢2y ago
we will get to that later
SteliosKrom
SteliosKromOPā€¢2y ago
It is not an int or a float Ok
TheRanger
TheRangerā€¢2y ago
what happened to the field difficulty ? u deleted it?
SteliosKrom
SteliosKromOPā€¢2y ago
no it is in game manager
TheRanger
TheRangerā€¢2y ago
i told you this but you deleted it instead
SteliosKrom
SteliosKromOPā€¢2y ago
I did that in game manager
TheRanger
TheRangerā€¢2y ago
keep the one in DifficultyButton class to too so each button has its own Difficulty value, to assign to the one in GameManager later
SteliosKrom
SteliosKromOPā€¢2y ago
Do i have to remove it from game manager?
TheRanger
TheRangerā€¢2y ago
No
SteliosKrom
SteliosKromOPā€¢2y ago
oh ok It says difficulty button It doesn't have the Difficulty
TheRanger
TheRangerā€¢2y ago
what?
SteliosKrom
SteliosKromOPā€¢2y ago
that in difficulty script
TheRanger
TheRangerā€¢2y ago
show new screenshot
SteliosKrom
SteliosKromOPā€¢2y ago
TheRanger
TheRangerā€¢2y ago
well where did u define the enum? you did the same mistake before, u sure are forgetful
SteliosKrom
SteliosKromOPā€¢2y ago
I am not forgetfull i just lose control easy cuz I dont know I just do it first itme time I couldn't have done that alone I will take some lessons soon To learn more but ok
TheRanger
TheRangerā€¢2y ago
i believe you defined it in GameManager, right? put it outside the class atleast the enum type that is
SteliosKrom
SteliosKromOPā€¢2y ago
yes
public enum Difficulty
{
easy,
medium,
hard
}
public enum Difficulty
{
easy,
medium,
hard
}
Here i did that In game manager
TheRanger
TheRangerā€¢2y ago
capitalize each first letter of easy, medium and hard
SteliosKrom
SteliosKromOPā€¢2y ago
I have also that in game manager public Difficulty difficulty; now in difficulty script I capitalize them
TheRanger
TheRangerā€¢2y ago
ok
SteliosKrom
SteliosKromOPā€¢2y ago
Now which variable do i have to create in difficulty script
TheRanger
TheRangerā€¢2y ago
what do u mean?
SteliosKrom
SteliosKromOPā€¢2y ago
public class DifficultyButton : MonoBehaviour
{
private Button button;
private GameManager gameManager;

// Start is called before the first frame update
void Start()
{
button = GetComponent<Button>();
gameManager = GameObject.Find("GameManager").GetComponent<GameManager>();
button.onClick.AddListener(SetDifficulty);
}

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

}

void SetDifficulty()
{
Debug.Log(button.gameObject.name + " was clicked");
gameManager.StartGame(difficulty);
}

}
public class DifficultyButton : MonoBehaviour
{
private Button button;
private GameManager gameManager;

// Start is called before the first frame update
void Start()
{
button = GetComponent<Button>();
gameManager = GameObject.Find("GameManager").GetComponent<GameManager>();
button.onClick.AddListener(SetDifficulty);
}

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

}

void SetDifficulty()
{
Debug.Log(button.gameObject.name + " was clicked");
gameManager.StartGame(difficulty);
}

}
I have that the difficulty is an error
TheRanger
TheRangerā€¢2y ago
put public Difficulty difficulty; error because difficulty variable does not exist in this class
SteliosKrom
SteliosKromOPā€¢2y ago
I cant use the Difficulty in this class Thats the problem
TheRanger
TheRangerā€¢2y ago
why not? oh u defined the enum in GameManager class right?
SteliosKrom
SteliosKromOPā€¢2y ago
yes It does not allow
TheRanger
TheRangerā€¢2y ago
so
public GameManager.Difficulty difficulty;
public GameManager.Difficulty difficulty;
for you
SteliosKrom
SteliosKromOPā€¢2y ago
Like i did before I told you that You said thats ugly
TheRanger
TheRangerā€¢2y ago
Yeah thats why you need to define the enum in its own file atleast
SteliosKrom
SteliosKromOPā€¢2y ago
I did that
TheRanger
TheRangerā€¢2y ago
can you show?
SteliosKrom
SteliosKromOPā€¢2y ago
in the other class and I told you to make public gamemanager.difficulty bluh bluh and you said that it is ugly to do so i removed it and waited
TheRanger
TheRangerā€¢2y ago
it is
SteliosKrom
SteliosKromOPā€¢2y ago
I will add it again wait
TheRanger
TheRangerā€¢2y ago
and i believe i told u to define it in its own file or outside the GameManager class
SteliosKrom
SteliosKromOPā€¢2y ago
public GameManager.Difficulty difficulty; I did that
TheRanger
TheRangerā€¢2y ago
so... ur not gonna define it in its own file?
SteliosKrom
SteliosKromOPā€¢2y ago
Oh how to define it in its own file??
TheRanger
TheRangerā€¢2y ago
create a new .cs file just like u did with the rest of the scripts? in the Assets/Scripts folder if you have GameManager.cs
SteliosKrom
SteliosKromOPā€¢2y ago
ok
TheRanger
TheRangerā€¢2y ago
and DifficulyButton.cs
SteliosKrom
SteliosKromOPā€¢2y ago
yes
TheRanger
TheRangerā€¢2y ago
u can also have Difficulty.cs
SteliosKrom
SteliosKromOPā€¢2y ago
ok so to make a script or a folder?
TheRanger
TheRangerā€¢2y ago
make a script
SteliosKrom
SteliosKromOPā€¢2y ago
ok I call it Difficulty
TheRanger
TheRangerā€¢2y ago
.cs ? the file extension is important
SteliosKrom
SteliosKromOPā€¢2y ago
Oh ok
TheRanger
TheRangerā€¢2y ago
so Unity can know its a csharp file
SteliosKrom
SteliosKromOPā€¢2y ago
Ok I call it Difficulty.cs Now what i do
TheRanger
TheRangerā€¢2y ago
ok nice, is it in Assets/Scripts folder like the rest of the files?
SteliosKrom
SteliosKromOPā€¢2y ago
yes
TheRanger
TheRangerā€¢2y ago
u put
public enum Difficulty
{
Easy,
Medium,
Hard
}
public enum Difficulty
{
Easy,
Medium,
Hard
}
in that file
SteliosKrom
SteliosKromOPā€¢2y ago
so i remove it from game maanger manager ?
TheRanger
TheRangerā€¢2y ago
yes
SteliosKrom
SteliosKromOPā€¢2y ago
ok where to put it in start() or in update() ? or before start oh nothing Understood I made my own
TheRanger
TheRangerā€¢2y ago
put what?
SteliosKrom
SteliosKromOPā€¢2y ago
outside of thos those nothing nevermind I did that I put it insdie inside Now i do have to get reference?
TheRanger
TheRangerā€¢2y ago
now u can safely define public Difficulty difficulty; in DifficultyScript since the enum isnt in the GameManager anymore
SteliosKrom
SteliosKromOPā€¢2y ago
oh in my DifficultyButton script right?
TheRanger
TheRangerā€¢2y ago
yes
SteliosKrom
SteliosKromOPā€¢2y ago
I did that I cant divide the difficulty with spawn rate Still have an error with that I did what you said but I got only one error
SteliosKrom
SteliosKromOPā€¢2y ago
SteliosKrom
SteliosKromOPā€¢2y ago
We will continue later I have to go. I will read your messages later on Bye, thanks!
TheRanger
TheRangerā€¢2y ago
yeah you will not divide the difficulty you will use if else or switch statements
if (difficulty == Difficulty.Easy)
{
spawnRate = 0.2f;
}
if (difficulty == Difficulty.Easy)
{
spawnRate = 0.2f;
}
for example
SteliosKrom
SteliosKromOPā€¢2y ago
Hey, I am back I did that but it give me an error I will show you, let me open visual and unity
SteliosKrom
SteliosKromOPā€¢2y ago
SteliosKrom
SteliosKromOPā€¢2y ago
So, I did that I name it difficulties not Difficulty i had a name called that so I change it if (difficulty == Difficulty.Difficulties.Easy) This also get me an error
SteliosKrom
SteliosKromOPā€¢2y ago
SteliosKrom
SteliosKromOPā€¢2y ago
@TheRanger
TheRanger
TheRangerā€¢2y ago
is ur enum named Difficulty or Difficulties?
SteliosKrom
SteliosKromOPā€¢2y ago
my enum named difficulties
TheRanger
TheRangerā€¢2y ago
talking about this the type itself
SteliosKrom
SteliosKromOPā€¢2y ago
yeah
TheRanger
TheRangerā€¢2y ago
i cant see the error fully
SteliosKrom
SteliosKromOPā€¢2y ago
I call it difficulties, I ve deleted the script and made a new one again difficulty.cs and then i call the enum difficulties I will show you Wait
TheRanger
TheRangerā€¢2y ago
can u show that file?
SteliosKrom
SteliosKromOPā€¢2y ago
You want me to make the if statement in a method that already exists or in a new one for example SaveHighScoreForEachDifficulty() and also in which script to do that?
TheRanger
TheRangerā€¢2y ago
the if statement is suppose to be in StartGame method
SteliosKrom
SteliosKromOPā€¢2y ago
Ok but i can make a method and call it in there in startgame() right? Wait i will show you the file
SteliosKrom
SteliosKromOPā€¢2y ago
TheRanger
TheRangerā€¢2y ago
do not define enums in a class as ive said before what do u need that class for?
SteliosKrom
SteliosKromOPā€¢2y ago
The difficulty you mean?
TheRanger
TheRangerā€¢2y ago
and why do u need it to inherit from MonoBehaviour?
SteliosKrom
SteliosKromOPā€¢2y ago
Don't you said to make the enum in difficulty.cs?
TheRanger
TheRangerā€¢2y ago
yes, ur point? that file should only have
public enum Difficulty
{
Easy,
Medium,
Hard
}
public enum Difficulty
{
Easy,
Medium,
Hard
}
with nothing around it
SteliosKrom
SteliosKromOPā€¢2y ago
I don't need mono behaviour? What is actually mono behaviour? I have never thought about what it does
TheRanger
TheRangerā€¢2y ago
its for Unity to detect it as a Unity script
SteliosKrom
SteliosKromOPā€¢2y ago
oh wait I read it Thats clearly understandable
TheRanger
TheRangerā€¢2y ago
to allow you to attach it to game objects
SteliosKrom
SteliosKromOPā€¢2y ago
yeah
TheRanger
TheRangerā€¢2y ago
and detect methods like Start and Update method to call them
SteliosKrom
SteliosKromOPā€¢2y ago
So, I dont want it to be attached in game objects so thats why I have to remove it?
TheRanger
TheRangerā€¢2y ago
nope, the Enum is only a value type yes
SteliosKrom
SteliosKromOPā€¢2y ago
Alright, understood!
TheRanger
TheRangerā€¢2y ago
brb 30 minutes
SteliosKrom
SteliosKromOPā€¢2y ago
ok bb
TheRanger
TheRangerā€¢2y ago
back where were we?
SteliosKrom
SteliosKromOPā€¢2y ago
Yes i did that check We have to be fast because I have school and I haven't finished homework that my teacher assigned to me So check
SteliosKrom
SteliosKromOPā€¢2y ago
SteliosKrom
SteliosKromOPā€¢2y ago
I did that in the method I cut everything i had in checksavehighscore method and put it in this one Hey are you there?
TheRanger
TheRangerā€¢2y ago
yeah
SteliosKrom
SteliosKromOPā€¢2y ago
I delete it and I add it again in checksavehighscore i notice a problem in that check save highscore method it is for game over check not in start game i dont want it to be saved in the start We are there were we left it So, what are the next steps ?
TheRanger
TheRangerā€¢2y ago
does this method work as u wanted to?
SteliosKrom
SteliosKromOPā€¢2y ago
let me chck
SteliosKrom
SteliosKromOPā€¢2y ago
SteliosKrom
SteliosKromOPā€¢2y ago
I have that problem in console I made three variables floats for spawn rate for each difficulty
TheRanger
TheRangerā€¢2y ago
and?
SteliosKrom
SteliosKromOPā€¢2y ago
I made them private variables and I did assigned a value
TheRanger
TheRangerā€¢2y ago
ok? read the message those are warnings not errors its telling you you never used them
SteliosKrom
SteliosKromOPā€¢2y ago
I made it public and it fixed i know they are not errors
TheRanger
TheRangerā€¢2y ago
ok
SteliosKrom
SteliosKromOPā€¢2y ago
So, now what i do ?
MODiX
MODiXā€¢2y ago
TheRanger#3357
does this method work as u wanted to?
React with āŒ to remove this embed.
SteliosKrom
SteliosKromOPā€¢2y ago
no it doesn't worked
TheRanger
TheRangerā€¢2y ago
try to debug and see where the issue is
SteliosKrom
SteliosKromOPā€¢2y ago
For one reason my difficulty is the same for each diff I assigned the values
TheRanger
TheRangerā€¢2y ago
first, check which if condition does it call for each difficulty u set
Debug.Log("The Easy If condition was called")
Debug.Log("The Easy If condition was called")
start by putting that in the if condition of easy difficulty for example
SteliosKrom
SteliosKromOPā€¢2y ago
I need a bol bool isclicked I think It works I wrote debug.log and it shows that in the console the click works but the game has no difficulty for a reason also does not save in start game
TheRanger
TheRangerā€¢2y ago
default difficulty is easy if you never set it
SteliosKrom
SteliosKromOPā€¢2y ago
only in game over and then reload scene nothing happens
TheRanger
TheRangerā€¢2y ago
it cant have no difficulty
SteliosKrom
SteliosKromOPā€¢2y ago
I made three varibles spawnrate for easy for med and hard
TheRanger
TheRangerā€¢2y ago
what is the goal of this method?
SteliosKrom
SteliosKromOPā€¢2y ago
It checks and if it is easy then it saves updates the score in start game it is wrong actually
TheRanger
TheRangerā€¢2y ago
when do u call this method?
SteliosKrom
SteliosKromOPā€¢2y ago
BlazeBin
A tool for sharing your source code with the world!
SteliosKrom
SteliosKromOPā€¢2y ago
This is the game manager script check the last method
TheRanger
TheRangerā€¢2y ago
? i see no code there, thats the home page of the website
SteliosKrom
SteliosKromOPā€¢2y ago
XD wait
SteliosKrom
SteliosKromOPā€¢2y ago
BlazeBin - qxuipuejrjqo
A tool for sharing your source code with the world!
SteliosKrom
SteliosKromOPā€¢2y ago
I have also that script that i didn't show you
SteliosKrom
SteliosKromOPā€¢2y ago
BlazeBin - xrstnejhjqpq
A tool for sharing your source code with the world!
SteliosKrom
SteliosKromOPā€¢2y ago
It is where i destroy out of bounds target and game over and everything I call from game maanger manager
TheRanger
TheRangerā€¢2y ago
ur calling SaveHighScoreForEachDifficulty method when u click start game?
SteliosKrom
SteliosKromOPā€¢2y ago
Yes Thats not right ?
TheRanger
TheRangerā€¢2y ago
oh u modified the method it looked like this moments ago
SteliosKrom
SteliosKromOPā€¢2y ago
I change it and get back where I was before
TheRanger
TheRangerā€¢2y ago
ok so, when u open the game what do you see?
SteliosKrom
SteliosKromOPā€¢2y ago
I add only that in save high score method I have not diff
TheRanger
TheRangerā€¢2y ago
make up ur mind already šŸ˜…
SteliosKrom
SteliosKromOPā€¢2y ago
the score doesn't save on reload XD
TheRanger
TheRangerā€¢2y ago
lets take steps when u open the game, what do u see?
SteliosKrom
SteliosKromOPā€¢2y ago
When I open the game i see in score = 0 and highscore = 0 as well and the menu screen
TheRanger
TheRangerā€¢2y ago
can u show screenshot?
SteliosKrom
SteliosKromOPā€¢2y ago
SteliosKrom
SteliosKromOPā€¢2y ago
Check Wanna a video
TheRanger
TheRangerā€¢2y ago
ok did you give difficulty values for each difficulty button?
SteliosKrom
SteliosKromOPā€¢2y ago
video record how the game starts and ends?
TheRanger
TheRangerā€¢2y ago
not now
MODiX
MODiXā€¢2y ago
TheRanger#3357
ok did you give difficulty values for each difficulty button?
React with āŒ to remove this embed.
SteliosKrom
SteliosKromOPā€¢2y ago
Yes In game manager script I add them
TheRanger
TheRangerā€¢2y ago
can u screenshot that?
SteliosKrom
SteliosKromOPā€¢2y ago
I have them in there as well
SteliosKrom
SteliosKromOPā€¢2y ago
SteliosKrom
SteliosKromOPā€¢2y ago
here as well I have these variables public
TheRanger
TheRangerā€¢2y ago
ok so Difficulty is Medium for Medium button, and Hard for Hard button?
SteliosKrom
SteliosKromOPā€¢2y ago
Wait I did something wrong Spawnrateeasy in hardbutton
TheRanger
TheRangerā€¢2y ago
that doesnt look like the inspector window of the difficulty button
SteliosKrom
SteliosKromOPā€¢2y ago
Wait a minute
TheRanger
TheRangerā€¢2y ago
click on one of these buttons and show me their inspector window
SteliosKrom
SteliosKromOPā€¢2y ago
I found the problem I didn't change the difficulty in buttons XD easy in all buttons i have
TheRanger
TheRangerā€¢2y ago
show me that you did
SteliosKrom
SteliosKromOPā€¢2y ago
SteliosKrom
SteliosKromOPā€¢2y ago
SteliosKrom
SteliosKromOPā€¢2y ago
I just changed it
TheRanger
TheRangerā€¢2y ago
ok cool now each button has their own difficulty value show the DifficultyButton script
SteliosKrom
SteliosKromOPā€¢2y ago
Still doesn't change the diff
TheRanger
TheRangerā€¢2y ago
yea we will get there take steps
SteliosKrom
SteliosKromOPā€¢2y ago
yes
TheRanger
TheRangerā€¢2y ago
step 2, DifficultyButton script, show it
SteliosKrom
SteliosKromOPā€¢2y ago
TheRanger
TheRangerā€¢2y ago
ok do u know why the difficulty didnt change?
SteliosKrom
SteliosKromOPā€¢2y ago
oh i didn't call it in setdifficulty
TheRanger
TheRangerā€¢2y ago
no
SteliosKrom
SteliosKromOPā€¢2y ago
in start() sorry
TheRanger
TheRangerā€¢2y ago
you do call it as a proof, StartGame method gets called right? that calls the SaveHighScoreForEachDifficulty, right?
SteliosKrom
SteliosKromOPā€¢2y ago
yes yes
TheRanger
TheRangerā€¢2y ago
the
if (difficulty == Difficulties.Easy && !isClicked)
{
spawnRateEasy = 0.7f;
Debug.Log("The button easy was clicked!");
}
if (difficulty == Difficulties.Easy && !isClicked)
{
spawnRateEasy = 0.7f;
Debug.Log("The button easy was clicked!");
}
the difficulty here is easy because you never gave it a value this is public Difficulties difficulty;'s variable
SteliosKrom
SteliosKromOPā€¢2y ago
yes
TheRanger
TheRangerā€¢2y ago
not the one who came from the parameter StartGame
SteliosKrom
SteliosKromOPā€¢2y ago
oh So the parameter comes from start game i need ?
TheRanger
TheRangerā€¢2y ago
yes u have 2 ways
SteliosKrom
SteliosKromOPā€¢2y ago
No i have set it difficulties the enum I cant divide like i said before
TheRanger
TheRangerā€¢2y ago
assign the difficulty from StartGame's difficulty why are u so obsessed with dividing
SteliosKrom
SteliosKromOPā€¢2y ago
anyway ok i will do it XD
TheRanger
TheRangerā€¢2y ago
u either do
public void StartGame(Difficulties difficulty)
{
this.difficulty = difficulty; // this was added

if (PlayerPrefs.HasKey("HighScore"))
{
highScore = PlayerPrefs.GetInt("HighScore");
}

isGameActive = true;
score = 0;
StartCoroutine(SpawnTarget());
UpdateScore(0);
UpdateHighScore(highScore);
SaveHighScoreForEachDifficulty();
menuScreen.gameObject.SetActive(false);
Debug.Log("The game started!");
}
public void StartGame(Difficulties difficulty)
{
this.difficulty = difficulty; // this was added

if (PlayerPrefs.HasKey("HighScore"))
{
highScore = PlayerPrefs.GetInt("HighScore");
}

isGameActive = true;
score = 0;
StartCoroutine(SpawnTarget());
UpdateScore(0);
UpdateHighScore(highScore);
SaveHighScoreForEachDifficulty();
menuScreen.gameObject.SetActive(false);
Debug.Log("The game started!");
}
or
public void StartGame(Difficulties difficulty)
{

if (PlayerPrefs.HasKey("HighScore"))
{
highScore = PlayerPrefs.GetInt("HighScore");
}

isGameActive = true;
score = 0;
StartCoroutine(SpawnTarget());
UpdateScore(0);
UpdateHighScore(highScore);
SaveHighScoreForEachDifficulty(difficulty); // <<<<<<<<<<<<<< here
menuScreen.gameObject.SetActive(false);
Debug.Log("The game started!");
}
public void StartGame(Difficulties difficulty)
{

if (PlayerPrefs.HasKey("HighScore"))
{
highScore = PlayerPrefs.GetInt("HighScore");
}

isGameActive = true;
score = 0;
StartCoroutine(SpawnTarget());
UpdateScore(0);
UpdateHighScore(highScore);
SaveHighScoreForEachDifficulty(difficulty); // <<<<<<<<<<<<<< here
menuScreen.gameObject.SetActive(false);
Debug.Log("The game started!");
}
SteliosKrom
SteliosKromOPā€¢2y ago
yeah i didn't add the parameter in save highscore no
TheRanger
TheRangerā€¢2y ago
so, u either take the value from the parameter and add it to the field
SteliosKrom
SteliosKromOPā€¢2y ago
it its not that
TheRanger
TheRangerā€¢2y ago
or u pass it as a parameter to the SaveHighScoreForEachDifficulty method
SteliosKrom
SteliosKromOPā€¢2y ago
SteliosKrom
SteliosKromOPā€¢2y ago
it says that error when i want to pass the parameter to the method
TheRanger
TheRangerā€¢2y ago
u should know what it means add the parameter to the method
SteliosKrom
SteliosKromOPā€¢2y ago
it says no overload i add it
TheRanger
TheRangerā€¢2y ago
show me how u added it
SteliosKrom
SteliosKromOPā€¢2y ago
TheRanger
TheRangerā€¢2y ago
public void SaveHighScoreForEachDifficulty(Difficulty difficulty)
public void SaveHighScoreForEachDifficulty(Difficulty difficulty)
SteliosKrom
SteliosKromOPā€¢2y ago
ok wait
TheRanger
TheRangerā€¢2y ago
now the difficulty variable in that method, will be the one in the parameter, not the field or just use this way since u need to tell the game which difficulty to set
SteliosKrom
SteliosKromOPā€¢2y ago
ok now it fixed i got another error in target script
SteliosKrom
SteliosKromOPā€¢2y ago
TheRanger
TheRangerā€¢2y ago
it needs an argument
SteliosKrom
SteliosKromOPā€¢2y ago
where i call it in destroy out of bound so when it does game over what to add difficulty?
TheRanger
TheRangerā€¢2y ago
brb
SteliosKrom
SteliosKromOPā€¢2y ago
I have to leave very soon willl you be at night 9:00 or 10:00 to try to fix that problem with me?
TheRanger
TheRangerā€¢2y ago
look it looks like ur just copy pasting my code without knowing what it does or how it works learn C# before starting unity
SteliosKrom
SteliosKromOPā€¢2y ago
I cant right now learn all of that
TheRanger
TheRangerā€¢2y ago
take ur time
SteliosKrom
SteliosKromOPā€¢2y ago
Yes i will do that in summer I have some exams thats why in 1 month
TheRanger
TheRangerā€¢2y ago
what does exams have to do with this game?
SteliosKrom
SteliosKromOPā€¢2y ago
I am trying to do simultaneously and the game and study for exams but I wanted to do that last thing and actually done with that until i give the exams
TheRanger
TheRangerā€¢2y ago
why not delay it to summer?
SteliosKrom
SteliosKromOPā€¢2y ago
Ok it will be right here the post
TheRanger
TheRangerā€¢2y ago
usually spoon feeding isnt allowed here
SteliosKrom
SteliosKromOPā€¢2y ago
So we will continue maybe 12 june when i will done? So do you want me to delete it for now
TheRanger
TheRangerā€¢2y ago
you could start learning the basics of C# in link below $helloworld
SteliosKrom
SteliosKromOPā€¢2y ago
Yes I have some platforms also solo learn and w3schools Anyway do i have to del that thread?
TheRanger
TheRangerā€¢2y ago
taake ur time, u wont learn if youre trying to learn too fast and skip steps
SteliosKrom
SteliosKromOPā€¢2y ago
for now?
TheRanger
TheRangerā€¢2y ago
no, you dont have to
SteliosKrom
SteliosKromOPā€¢2y ago
So, I will have it right here
TheRanger
TheRangerā€¢2y ago
u cant anyway
SteliosKrom
SteliosKromOPā€¢2y ago
oh ok Thanks for your help! I will contact you after 12 jun maybe if i will continue with that game ok ?
TheRanger
TheRangerā€¢2y ago
thats fine, tho anyone can help you
SteliosKrom
SteliosKromOPā€¢2y ago
Hey, how old are you? I am going in 9 days 18
TheRanger
TheRangerā€¢2y ago
why do u ask?
SteliosKrom
SteliosKromOPā€¢2y ago
I just ask Is there a problem to tell me how old you are? If yes tell me where is the problem?
TheRanger
TheRangerā€¢2y ago
it is a secret
SteliosKrom
SteliosKromOPā€¢2y ago
Come on I am not gonna tell it to anybody Trust me
TheRanger
TheRangerā€¢2y ago
thats not the issue
SteliosKrom
SteliosKromOPā€¢2y ago
Where are you from? I am from greece. Hey, I have some time I return from school Can you help me complete last thing I have some time free I don't want to delete it and start from the start after 12th june I left it now in the middle and I want to complete the last thing
TheRanger
TheRangerā€¢2y ago
what thing?
SteliosKrom
SteliosKromOPā€¢2y ago
I want to complete that with difficulties And then i close this thread
TheRanger
TheRangerā€¢2y ago
which part exactly?
SteliosKrom
SteliosKromOPā€¢2y ago
So, I still got the problem with the values my diff doesn't respond properly it is the same in all diffs
TheRanger
TheRangerā€¢2y ago
how so? show some code
SteliosKrom
SteliosKromOPā€¢2y ago
ok
public void SaveHighScoreForEachDifficulty(Difficulties difficulty)
{
if (difficulty == Difficulties.Easy && !isClicked)
{
PlayerPrefs.SetInt("highScore", highScore);
PlayerPrefs.Save();
spawnRateEasy = 0.7f;
Debug.Log("The button easy was clicked!");
}

else if (difficulty == Difficulties.Medium && !isClicked)
{
spawnRateMedium = 1.4f;
Debug.Log("The button medium was clicked!");
}

else if (difficulty == Difficulties.Hard && !isClicked)
{
SpawnRateHard = 2.1f;
Debug.Log("The button hard was clicked!");
}

}
public void SaveHighScoreForEachDifficulty(Difficulties difficulty)
{
if (difficulty == Difficulties.Easy && !isClicked)
{
PlayerPrefs.SetInt("highScore", highScore);
PlayerPrefs.Save();
spawnRateEasy = 0.7f;
Debug.Log("The button easy was clicked!");
}

else if (difficulty == Difficulties.Medium && !isClicked)
{
spawnRateMedium = 1.4f;
Debug.Log("The button medium was clicked!");
}

else if (difficulty == Difficulties.Hard && !isClicked)
{
SpawnRateHard = 2.1f;
Debug.Log("The button hard was clicked!");
}

}
So that is the savehighscoreforeachdiff() I ve added the parameter in there so I have it done Here difficultbutton script
public Difficulties difficulty;
private Button button;
private GameManager gameManager;

// Start is called before the first frame update
void Start()
{
button = GetComponent<Button>();
gameManager = GameObject.Find("GameManager").GetComponent<GameManager>();
button.onClick.AddListener(SetDifficulty);
}

void SetDifficulty()
{
Debug.Log(button.gameObject.name + " was clicked");
gameManager.StartGame(difficulty);
}

}
public Difficulties difficulty;
private Button button;
private GameManager gameManager;

// Start is called before the first frame update
void Start()
{
button = GetComponent<Button>();
gameManager = GameObject.Find("GameManager").GetComponent<GameManager>();
button.onClick.AddListener(SetDifficulty);
}

void SetDifficulty()
{
Debug.Log(button.gameObject.name + " was clicked");
gameManager.StartGame(difficulty);
}

}
TheRanger
TheRangerā€¢2y ago
so what current issue are u running into at the moment?
SteliosKrom
SteliosKromOPā€¢2y ago
public void StartGame(Difficulties difficulty)
{

if (PlayerPrefs.HasKey("HighScore"))
{
highScore = PlayerPrefs.GetInt("HighScore");
}

isGameActive = true;
score = 0;
StartCoroutine(SpawnTarget());
UpdateScore(0);
UpdateHighScore(highScore);
SaveHighScoreForEachDifficulty(difficulty);
menuScreen.gameObject.SetActive(false);
Debug.Log("The game started!");
}
public void StartGame(Difficulties difficulty)
{

if (PlayerPrefs.HasKey("HighScore"))
{
highScore = PlayerPrefs.GetInt("HighScore");
}

isGameActive = true;
score = 0;
StartCoroutine(SpawnTarget());
UpdateScore(0);
UpdateHighScore(highScore);
SaveHighScoreForEachDifficulty(difficulty);
menuScreen.gameObject.SetActive(false);
Debug.Log("The game started!");
}
here is the start game method i am sending you all of that in


because I dont want everytime taking screenshots thats better So, at the moment i have the problem with difficulties I click easy it has default diff, i click the medium it has again the default Every one of the button when gets clicked the value is default
TheRanger
TheRangerā€¢2y ago
u mean when u click hard, it prints "The button easy was clicked!" ?
SteliosKrom
SteliosKromOPā€¢2y ago
yeah It shows that in cosnole console But the value is default The spawn rate is the same in all of them Easy, medium and hard
TheRanger
TheRangerā€¢2y ago
u probably didnt set each button's difficulty value in their inspector window
SteliosKrom
SteliosKromOPā€¢2y ago
SteliosKrom
SteliosKromOPā€¢2y ago
Check i ve set it spawn rate easy
TheRanger
TheRangerā€¢2y ago
which button is that?
SteliosKrom
SteliosKromOPā€¢2y ago
it is the game manager inspector game manager object
TheRanger
TheRangerā€¢2y ago
yeah for which button is this inspector window showing info of? in this image
SteliosKrom
SteliosKromOPā€¢2y ago
easy it shows easy in diff
TheRanger
TheRangerā€¢2y ago
show medium and hard
SteliosKrom
SteliosKromOPā€¢2y ago
and it has its values in spawn rate ez mid and hard buttons?
TheRanger
TheRangerā€¢2y ago
yes
SteliosKrom
SteliosKromOPā€¢2y ago
SteliosKrom
SteliosKromOPā€¢2y ago
TheRanger
TheRangerā€¢2y ago
this medium?
SteliosKrom
SteliosKromOPā€¢2y ago
SteliosKrom
SteliosKromOPā€¢2y ago
first easy second mid third hard
TheRanger
TheRangerā€¢2y ago
so when u click hard it prints ``The button easy was clicked!" ?
SteliosKrom
SteliosKromOPā€¢2y ago
wait let me check I wrote debug.log in the method so i will check it it says the button hard is click clicked when i click hard
TheRanger
TheRangerā€¢2y ago
ok so its working
SteliosKrom
SteliosKromOPā€¢2y ago
Medium button was clicked when i click mid so yes it works But it spawns in the same rate
TheRanger
TheRangerā€¢2y ago
can u show code of gamemanager
SteliosKrom
SteliosKromOPā€¢2y ago
yes the whole ?
TheRanger
TheRangerā€¢2y ago
yes
SteliosKrom
SteliosKromOPā€¢2y ago
BlazeBin - iqzprnwnspso
A tool for sharing your source code with the world!
SteliosKrom
SteliosKromOPā€¢2y ago
check
TheRanger
TheRangerā€¢2y ago
yeah u are assigning values to fields spawnRateEasy, spawnRateMedium, and SpawnRateHard
SteliosKrom
SteliosKromOPā€¢2y ago
yes
TheRanger
TheRangerā€¢2y ago
but u are using the field spawnRate to spawn with
SteliosKrom
SteliosKromOPā€¢2y ago
yes
TheRanger
TheRangerā€¢2y ago
as seen in line 46 yield return new WaitForSeconds(spawnRate); spawnRate's value is 1.0
SteliosKrom
SteliosKromOPā€¢2y ago
yeah true yeah
TheRanger
TheRangerā€¢2y ago
because u set its value in private float spawnRate = 1.0f; but you never changed its value in the SaveHighScoreForEachDifficulty method and thats why the spawnrate is still the same
SteliosKrom
SteliosKromOPā€¢2y ago
yes but i have different variables for eas, mid and hard
TheRanger
TheRangerā€¢2y ago
pointless, u dont need them
SteliosKrom
SteliosKromOPā€¢2y ago
oh ok
TheRanger
TheRangerā€¢2y ago
u arent even using them
SteliosKrom
SteliosKromOPā€¢2y ago
So, I have to replace that variables with spawnrate that i have
TheRanger
TheRangerā€¢2y ago
yes
SteliosKrom
SteliosKromOPā€¢2y ago
ok I have an error in target script
TheRanger
TheRangerā€¢2y ago
show what you changed first
SteliosKrom
SteliosKromOPā€¢2y ago
ok
public void SaveHighScoreForEachDifficulty(Difficulties difficulty)
{
if (difficulty == Difficulties.Easy && !isClicked)
{
PlayerPrefs.SetInt("highScore", highScore);
PlayerPrefs.Save();
spawnRate = 0.7f;
Debug.Log("The button easy was clicked!");
}

else if (difficulty == Difficulties.Medium && !isClicked)
{
spawnRate = 1.4f;
Debug.Log("The button medium was clicked!");
}

else if (difficulty == Difficulties.Hard && !isClicked)
{
spawnRate = 2.1f;
Debug.Log("The button hard was clicked!");
}

}
public void SaveHighScoreForEachDifficulty(Difficulties difficulty)
{
if (difficulty == Difficulties.Easy && !isClicked)
{
PlayerPrefs.SetInt("highScore", highScore);
PlayerPrefs.Save();
spawnRate = 0.7f;
Debug.Log("The button easy was clicked!");
}

else if (difficulty == Difficulties.Medium && !isClicked)
{
spawnRate = 1.4f;
Debug.Log("The button medium was clicked!");
}

else if (difficulty == Difficulties.Hard && !isClicked)
{
spawnRate = 2.1f;
Debug.Log("The button hard was clicked!");
}

}
I changed spawn rate variables the three i had to spawn rate only
TheRanger
TheRangerā€¢2y ago
so i assume it spawns correctly now right?
SteliosKrom
SteliosKromOPā€¢2y ago
How do you mean that? Correctly?
TheRanger
TheRangerā€¢2y ago
like the spawn rate isnt the same for each difficulty u choose
SteliosKrom
SteliosKromOPā€¢2y ago
No it is because i have an error
TheRanger
TheRangerā€¢2y ago
then u probably ran an old build
SteliosKrom
SteliosKromOPā€¢2y ago
Like i said with parameter probably
TheRanger
TheRangerā€¢2y ago
what error?
SteliosKrom
SteliosKromOPā€¢2y ago
wait
SteliosKrom
SteliosKromOPā€¢2y ago
SteliosKrom
SteliosKromOPā€¢2y ago
Check
TheRanger
TheRangerā€¢2y ago
yeah the method needs an argument to pass where are u calling that method?
SteliosKrom
SteliosKromOPā€¢2y ago
Yeah but which one i have the difficulty parameter do i have to use it? in game over and in start i have it there
TheRanger
TheRangerā€¢2y ago
why are u calling it? in game over
SteliosKrom
SteliosKromOPā€¢2y ago
You are right. It is pointless to have it there I have also one method that saves the highscore in game over I removed it from there So take a look
public void DestroyGoodOutOfBounds()
{
if (transform.position.y < yRange && gameObject.CompareTag("Good") && gameManager.isGameActive)
{
gameManager.isGameActive = false;
Destroy(gameObject);
gameManager.GameOver();
gameManager.StopPlayerAudioOnGameOver();
gameManager.CheckSaveHighScore();
gameManager.SaveHighScoreForEachDifficulty();
gameManager.highScoreText.text = "HighScore: " + gameManager.score;
Debug.Log("Good objects have been destroyed!");
}

}
public void DestroyGoodOutOfBounds()
{
if (transform.position.y < yRange && gameObject.CompareTag("Good") && gameManager.isGameActive)
{
gameManager.isGameActive = false;
Destroy(gameObject);
gameManager.GameOver();
gameManager.StopPlayerAudioOnGameOver();
gameManager.CheckSaveHighScore();
gameManager.SaveHighScoreForEachDifficulty();
gameManager.highScoreText.text = "HighScore: " + gameManager.score;
Debug.Log("Good objects have been destroyed!");
}

}
that was with the method I am calling that method only in start game right now
TheRanger
TheRangerā€¢2y ago
let me ask u again, what is the purpose of the SaveHighScoreForEachDifficulty method?
SteliosKrom
SteliosKromOPā€¢2y ago
The purpose is to save highscore in each difficulty
TheRanger
TheRangerā€¢2y ago
save it where?
SteliosKrom
SteliosKromOPā€¢2y ago
In the start game so whenever the game ends it will save the highscore in easy dif
TheRanger
TheRangerā€¢2y ago
what do u mean by the score end?
SteliosKrom
SteliosKromOPā€¢2y ago
so when the player wants to play again in the same dif then he continue from there where he left it Check it again whenever the game ends
TheRanger
TheRangerā€¢2y ago
so you want to save the high score when the game ends right?
SteliosKrom
SteliosKromOPā€¢2y ago
Yes i do it in game over with checksavehighscore method check here I want it to be saved when i restart the game and click again the diff button to play I will show you a video record
TheRanger
TheRangerā€¢2y ago
can u tell me what save highscore means
SteliosKrom
SteliosKromOPā€¢2y ago
save highscore means that whenever the game goes over the highscore is being saved it saves the current highscore player did
TheRanger
TheRangerā€¢2y ago
so why are u trying to save the highscore at the start of the game?
SteliosKrom
SteliosKromOPā€¢2y ago
I got confused, so i have to have the savehighscoreforeachdiff() somewhere else? Just leave that method alone in game manager ?
TheRanger
TheRangerā€¢2y ago
what do u think?
SteliosKrom
SteliosKromOPā€¢2y ago
Let me take you a video record You will understand the problem
TheRanger
TheRangerā€¢2y ago
k
SteliosKrom
SteliosKromOPā€¢2y ago
Tell me truly do I have bad english? Some people told me I have mid
TheRanger
TheRangerā€¢2y ago
mid i guess
SteliosKrom
SteliosKromOPā€¢2y ago
šŸ˜¦
TheRanger
TheRangerā€¢2y ago
where''s the video?
SteliosKrom
SteliosKromOPā€¢2y ago
Wait Do you know which is the best platform or app that I can use in order to video record? Maybe my windows 11 has that predownloaded?
TheRanger
TheRangerā€¢2y ago
idk screenshots should be fine tho ur suppose to load the high score of the current difficulty at the start of the game are u doing that?
SteliosKrom
SteliosKromOPā€¢2y ago
yes
SteliosKrom
SteliosKromOPā€¢2y ago
SteliosKrom
SteliosKromOPā€¢2y ago
I noticed something When i ve clicked medium I was the difficulty value of easy when i clicked easy it had faster spawn rate
TheRanger
TheRangerā€¢2y ago
yeah? we already solved that so ur current issue is
SteliosKrom
SteliosKromOPā€¢2y ago
We solved the spawn rate?
TheRanger
TheRangerā€¢2y ago
yes
SteliosKrom
SteliosKromOPā€¢2y ago
When I click easy it spawns faster than mid why?
TheRanger
TheRangerā€¢2y ago
because you told it so? 0.7 means an item will spawn every 0.7 seconds 1.4 means an item will spawn every 1.4 seconds
SteliosKrom
SteliosKromOPā€¢2y ago
Yes the opposite happens thats what i mean XD in mid where i have 1.4 happens the 0.7
TheRanger
TheRangerā€¢2y ago
are u sure?
SteliosKrom
SteliosKromOPā€¢2y ago
Wait a minute
TheRanger
TheRangerā€¢2y ago
i cant see the mouse in ur video so idk which button u clicked
SteliosKrom
SteliosKromOPā€¢2y ago
First is the easy
TheRanger
TheRangerā€¢2y ago
oh but i see the button being clicked
SteliosKrom
SteliosKromOPā€¢2y ago
after that is the mid
TheRanger
TheRangerā€¢2y ago
its correct in ur video medium = 1.4 easy = 0.7 i can see what button u clicked in the video in ur video, u played easy first, then medium so why are u saying the opposite happens?
SteliosKrom
SteliosKromOPā€¢2y ago
yes I understood the problem I just mixed that with the division i ve had before I got confused with that
TheRanger
TheRangerā€¢2y ago
ok so ur current problem is ur not loading the highscore at the start of the game
SteliosKrom
SteliosKromOPā€¢2y ago
Yea works Lets go to the other problem That was the problem s It solved Yeah Thats the problme I cant load the highscore at the start from my previous game i want it to be saved from my previous game in the new one in the same diff that i have started playing
TheRanger
TheRangerā€¢2y ago
well try creating a method called LoadHighScore
SteliosKrom
SteliosKromOPā€¢2y ago
oh ok
TheRanger
TheRangerā€¢2y ago
with a parameter of difficulty
SteliosKrom
SteliosKromOPā€¢2y ago
That i have made?
TheRanger
TheRangerā€¢2y ago
public void LoadHighScore(Difficulties difficulty)
SteliosKrom
SteliosKromOPā€¢2y ago
yeah
TheRanger
TheRangerā€¢2y ago
are u on windows?
SteliosKrom
SteliosKromOPā€¢2y ago
yes
TheRanger
TheRangerā€¢2y ago
open regedit in run command
SteliosKrom
SteliosKromOPā€¢2y ago
opened registry editor is opened
TheRanger
TheRangerā€¢2y ago
Expand HKey_Current_User
SteliosKrom
SteliosKromOPā€¢2y ago
yeah
TheRanger
TheRangerā€¢2y ago
then expand Software
SteliosKrom
SteliosKromOPā€¢2y ago
yeah
TheRanger
TheRangerā€¢2y ago
can u open this window in Unity ?
SteliosKrom
SteliosKromOPā€¢2y ago
yes
TheRanger
TheRangerā€¢2y ago
open it what is the company name and product name?
SteliosKrom
SteliosKromOPā€¢2y ago
TheRanger
TheRangerā€¢2y ago
ok back to regedit
SteliosKrom
SteliosKromOPā€¢2y ago
ok
TheRanger
TheRangerā€¢2y ago
under HKey_Current_User/Software u should see DefaultCompany is it there?
SteliosKrom
SteliosKromOPā€¢2y ago
I see it
TheRanger
TheRangerā€¢2y ago
expand it, then click MyGame what do u see?
SteliosKrom
SteliosKromOPā€¢2y ago
There is not mygame
TheRanger
TheRangerā€¢2y ago
u sure?
SteliosKrom
SteliosKromOPā€¢2y ago
I see new unity projects and playime laucnhed launched playtimelaucnher launcher
TheRanger
TheRangerā€¢2y ago
under DefaultCompany? did u expand DefaultCompany ?
SteliosKrom
SteliosKromOPā€¢2y ago
yes i told you what was in there
TheRanger
TheRangerā€¢2y ago
šŸ¤”
SteliosKrom
SteliosKromOPā€¢2y ago
it says default when i click defaultcompany Do i really need that? Why we want that?
TheRanger
TheRangerā€¢2y ago
can u run %userprofile%\AppData\Local\Packages\ in run ?
SteliosKrom
SteliosKromOPā€¢2y ago
YEs i can I see a lot of files microsoft related and more
TheRanger
TheRangerā€¢2y ago
one of the folders uses ur game's package id
SteliosKrom
SteliosKromOPā€¢2y ago
So, why we are doing that?
TheRanger
TheRangerā€¢2y ago
we want to see where the highscore gets stored
SteliosKrom
SteliosKromOPā€¢2y ago
ok do i have to find that In every file?
TheRanger
TheRangerā€¢2y ago
if ur on windows 10 or 11 its harder are u on any of these windows?
SteliosKrom
SteliosKromOPā€¢2y ago
iam on 11
TheRanger
TheRangerā€¢2y ago
nvm then
SteliosKrom
SteliosKromOPā€¢2y ago
anyway do i have to close that all?
TheRanger
TheRangerā€¢2y ago
yyeah u can close regedit
SteliosKrom
SteliosKromOPā€¢2y ago
Is there another way to see where it is stored?
TheRanger
TheRangerā€¢2y ago
so back to this
SteliosKrom
SteliosKromOPā€¢2y ago
yes
SteliosKrom
SteliosKromOPā€¢2y ago
SteliosKrom
SteliosKromOPā€¢2y ago
I ve got an error with that
TheRanger
TheRangerā€¢2y ago
well u can debug for example u save and load and debug the value
PlayerPrefs.SetInt("Foo",9999);
var foo = PlayerPrefs.GetInt("Foo", 2);
Debug.Log("Value is " + foo);
PlayerPrefs.SetInt("Foo",9999);
var foo = PlayerPrefs.GetInt("Foo", 2);
Debug.Log("Value is " + foo);
just for debugging purposes
SteliosKrom
SteliosKromOPā€¢2y ago
yes
TheRanger
TheRangerā€¢2y ago
try atleast executing that code when u open the game and tell me what it printed
SteliosKrom
SteliosKromOPā€¢2y ago
ok Can you tell me also what to do with that one
SteliosKrom
SteliosKromOPā€¢2y ago
TheRanger
TheRangerā€¢2y ago
we want to make sure if it saves and loads data from ur pc ignore that did u open unity twice or something?
SteliosKrom
SteliosKromOPā€¢2y ago
no why?
TheRanger
TheRangerā€¢2y ago
nvm then
SteliosKrom
SteliosKromOPā€¢2y ago
It seems like in the code above nothing happens
TheRanger
TheRangerā€¢2y ago
where did u put that code?
SteliosKrom
SteliosKromOPā€¢2y ago
no it happens Sorry it says value is 0 at the game over i did 60 highscore
TheRanger
TheRangerā€¢2y ago
i dont care about that atm did it print Value is 0 ?
SteliosKrom
SteliosKromOPā€¢2y ago
I mean i did 60 highscore and it says value is 60 i also dont care value is 0
TheRanger
TheRangerā€¢2y ago
this code?
SteliosKrom
SteliosKromOPā€¢2y ago
Where do you want me to put that code you send in which method? I ve putted where it checks and saves at the game over
TheRanger
TheRangerā€¢2y ago
well u can put it at StartGame method
SteliosKrom
SteliosKromOPā€¢2y ago
I will put it in both
TheRanger
TheRangerā€¢2y ago
doesnt reallyt matter, as long as it gets executed
SteliosKrom
SteliosKromOPā€¢2y ago
Yeah it says value is 0 at the game over
TheRanger
TheRangerā€¢2y ago
can u show the code?
SteliosKrom
SteliosKromOPā€¢2y ago
I ve putted in start game and in destroy out of bound where it goes game over
TheRanger
TheRangerā€¢2y ago
and the print message
SteliosKrom
SteliosKromOPā€¢2y ago
yes
public void StartGame(Difficulties difficulty)
{

if (PlayerPrefs.HasKey("HighScore"))
{
PlayerPrefs.SetInt("highScore", 9999);
var highscore = PlayerPrefs.GetInt("highScore", 0);
Debug.Log("Value is " + highScore);
highScore = PlayerPrefs.GetInt("HighScore");
}
public void StartGame(Difficulties difficulty)
{

if (PlayerPrefs.HasKey("HighScore"))
{
PlayerPrefs.SetInt("highScore", 9999);
var highscore = PlayerPrefs.GetInt("highScore", 0);
Debug.Log("Value is " + highScore);
highScore = PlayerPrefs.GetInt("HighScore");
}
here
SteliosKrom
SteliosKromOPā€¢2y ago
SteliosKrom
SteliosKromOPā€¢2y ago
Here is the console what shows So, we actually want to find where it saves the highscore with debug can i test that you send in other methods?
TheRanger
TheRangerā€¢2y ago
no no copy that exactly
PlayerPrefs.SetInt("Foo",9999);
var foo = PlayerPrefs.GetInt("Foo", 2);
Debug.Log("Value is " + foo);
PlayerPrefs.SetInt("Foo",9999);
var foo = PlayerPrefs.GetInt("Foo", 2);
Debug.Log("Value is " + foo);
SteliosKrom
SteliosKromOPā€¢2y ago
ok
TheRanger
TheRangerā€¢2y ago
dont put it in the if condition
SteliosKrom
SteliosKromOPā€¢2y ago
where ?
TheRanger
TheRangerā€¢2y ago
in the StartGame Method just not in the if condition
SteliosKrom
SteliosKromOPā€¢2y ago
Do i have to remove the previous one from both methods?
TheRanger
TheRangerā€¢2y ago
wont affect but sure the issue here is, u assigned value to highscore but you printed the value of highScore they are 2 different variables šŸ˜… thus why it printed 0
SteliosKrom
SteliosKromOPā€¢2y ago
oh
SteliosKrom
SteliosKromOPā€¢2y ago
SteliosKrom
SteliosKromOPā€¢2y ago
Check now it shows 9999 I did that you said i putted out of the if cond
TheRanger
TheRangerā€¢2y ago
ok cool so now we know it saves and loads fine delete the code and go back to the loadhighscore method
SteliosKrom
SteliosKromOPā€¢2y ago
yes so how to fix that with the 0 in the start game Just i have to change the highscore in player prefs? I set int highscore
TheRanger
TheRangerā€¢2y ago
lets take baby steps first go to the loadhighscore method
SteliosKrom
SteliosKromOPā€¢2y ago
I have an error there i have told you before method public is not valid for this item
TheRanger
TheRangerā€¢2y ago
show code?
SteliosKrom
SteliosKromOPā€¢2y ago
i have to remove the public modifier
public void LoadHighScore(Difficulties diff)
{

}
public void LoadHighScore(Difficulties diff)
{

}
waity wait
SteliosKrom
SteliosKromOPā€¢2y ago
SteliosKrom
SteliosKromOPā€¢2y ago
Check
public void StartGame(Difficulties difficulty)
{

if (PlayerPrefs.HasKey("HighScore"))
{
highScore = PlayerPrefs.GetInt("highScore", score);
}

isGameActive = true;
score = 0;
StartCoroutine(SpawnTarget());
UpdateScore(0);
UpdateHighScore(highScore);
SaveHighScoreForEachDifficulty(difficulty);
menuScreen.gameObject.SetActive(false);
Debug.Log("The game started!");
}

public void SaveHighScoreForEachDifficulty(Difficulties difficulty)
{
if (difficulty == Difficulties.Easy && !isClicked)
{
spawnRate = 2.1f;
Debug.Log("The button easy was clicked!");
}

else if (difficulty == Difficulties.Medium && !isClicked)
{
spawnRate = 1.4f;
Debug.Log("The button medium was clicked!");
}

else if (difficulty == Difficulties.Hard && !isClicked)
{
spawnRate = 0.7f;
Debug.Log("The button hard was clicked!");
}

public void LoadHighScore(Difficulties diff)
{

}

}
public void StartGame(Difficulties difficulty)
{

if (PlayerPrefs.HasKey("HighScore"))
{
highScore = PlayerPrefs.GetInt("highScore", score);
}

isGameActive = true;
score = 0;
StartCoroutine(SpawnTarget());
UpdateScore(0);
UpdateHighScore(highScore);
SaveHighScoreForEachDifficulty(difficulty);
menuScreen.gameObject.SetActive(false);
Debug.Log("The game started!");
}

public void SaveHighScoreForEachDifficulty(Difficulties difficulty)
{
if (difficulty == Difficulties.Easy && !isClicked)
{
spawnRate = 2.1f;
Debug.Log("The button easy was clicked!");
}

else if (difficulty == Difficulties.Medium && !isClicked)
{
spawnRate = 1.4f;
Debug.Log("The button medium was clicked!");
}

else if (difficulty == Difficulties.Hard && !isClicked)
{
spawnRate = 0.7f;
Debug.Log("The button hard was clicked!");
}

public void LoadHighScore(Difficulties diff)
{

}

}
Check the code Dont give attention to diff I write it difficulty and still the error exists oh I am an idiot I made the method in another method XD now its fine no errors So, lets take baby steps like you said moving on
TheRanger
TheRangerā€¢2y ago
you should know what to do by know
SteliosKrom
SteliosKromOPā€¢2y ago
So what i do now in load highscore can you tell me a little bit fast because i want to complete it no time for thinking and searching and all of that
TheRanger
TheRangerā€¢2y ago
cmon u already have the if condition and the playerprefs methods it doesnt even require thinking
SteliosKrom
SteliosKromOPā€¢2y ago
I have to get the if condition and the player prefs inside and paste them in load highscore? I dont think so
TheRanger
TheRangerā€¢2y ago
ull use if condition to check each difficulty and use playerPrefts GetInt to get each key for each difficulty and store the value to highScore careful, saying no time and be fast can get u muted here
SteliosKrom
SteliosKromOPā€¢2y ago
oh really Then sorry šŸ™‚
TheRanger
TheRangerā€¢2y ago
we're here to teach, not to spoon feed if you dont have time maybe you should just code it later
SteliosKrom
SteliosKromOPā€¢2y ago
Thats true my fault šŸ™‚ I know what to do just give me a sec but before i go there i want to know something I have already the SaveHighScore for each () and there i have if conditions so we make load highscore, so in load highscore i will save highscore in load so i will call that method in the Savehighscore mthod right?
TheRanger
TheRangerā€¢2y ago
baby steps lets finish the loadhighscore method first
SteliosKrom
SteliosKromOPā€¢2y ago
hahaha I love that you say babysteps It was steps now it is babysteps Ok anyway
public void LoadHighScore(Difficulties difficulty)
{
if (PlayerPrefs.HasKey("HighScore"))
{
highScore = PlayerPrefs.GetInt("highScore");
}

}
public void LoadHighScore(Difficulties difficulty)
{
if (PlayerPrefs.HasKey("HighScore"))
{
highScore = PlayerPrefs.GetInt("highScore");
}

}
I did that but I am not sure if it is correct
public void DifficultiesForEach(Difficulties difficulty)
{
if (difficulty == Difficulties.Easy && !isClicked)
{
spawnRate = 2.1f;
LoadHighScore(difficulty);
Debug.Log("The button easy was clicked!");
}

else if (difficulty == Difficulties.Medium && !isClicked)
{
spawnRate = 1.4f;
LoadHighScore(difficulty);
Debug.Log("The button medium was clicked!");
}

else if (difficulty == Difficulties.Hard && !isClicked)
{
spawnRate = 0.7f;
LoadHighScore(difficulty);
Debug.Log("The button hard was clicked!");
}

}
public void DifficultiesForEach(Difficulties difficulty)
{
if (difficulty == Difficulties.Easy && !isClicked)
{
spawnRate = 2.1f;
LoadHighScore(difficulty);
Debug.Log("The button easy was clicked!");
}

else if (difficulty == Difficulties.Medium && !isClicked)
{
spawnRate = 1.4f;
LoadHighScore(difficulty);
Debug.Log("The button medium was clicked!");
}

else if (difficulty == Difficulties.Hard && !isClicked)
{
spawnRate = 0.7f;
LoadHighScore(difficulty);
Debug.Log("The button hard was clicked!");
}

}
Also in that I ve added the load highscore
TheRanger
TheRangerā€¢2y ago
u never used the difficulty argument here
SteliosKrom
SteliosKromOPā€¢2y ago
You mean inside the loadhighscore method? or in the difficulties for each
TheRanger
TheRangerā€¢2y ago
yes inside the method
SteliosKrom
SteliosKromOPā€¢2y ago
I use it insdie inside the method
TheRanger
TheRangerā€¢2y ago
is this code still the same or changed?
SteliosKrom
SteliosKromOPā€¢2y ago
I changed something I did if condition
TheRanger
TheRangerā€¢2y ago
i wonder how it looks now
SteliosKrom
SteliosKromOPā€¢2y ago
I did something like that but I am not sure.
public void LoadHighScore(Difficulties difficulty)
{
if (difficulty == Difficulties.Easy && !isClicked && PlayerPrefs.HasKey("HighScore"))
{
highScore = PlayerPrefs.GetInt("highScore");
}

else if (difficulty == Difficulties.Medium &&)

}
public void LoadHighScore(Difficulties difficulty)
{
if (difficulty == Difficulties.Easy && !isClicked && PlayerPrefs.HasKey("HighScore"))
{
highScore = PlayerPrefs.GetInt("highScore");
}

else if (difficulty == Difficulties.Medium &&)

}
TheRanger
TheRangerā€¢2y ago
what does isClicked do?
SteliosKrom
SteliosKromOPā€¢2y ago
wait Give me some more hints please if you can
TheRanger
TheRangerā€¢2y ago
i just did
SteliosKrom
SteliosKromOPā€¢2y ago
I removed it
TheRanger
TheRangerā€¢2y ago
why did u put it in the first place?
SteliosKrom
SteliosKromOPā€¢2y ago
oh
TheRanger
TheRangerā€¢2y ago
??
SteliosKrom
SteliosKromOPā€¢2y ago
if (PlayerPrefs.HasKey("highScore") && difficulty == Difficulties.Easy)
{
highScore = PlayerPrefs.GetInt("highScore");
}
if (PlayerPrefs.HasKey("highScore") && difficulty == Difficulties.Easy)
{
highScore = PlayerPrefs.GetInt("highScore");
}
Maybe something like that
TheRanger
TheRangerā€¢2y ago
HasKey is redundant here as GetInt will return 0 if "highScore" wasnt stored in ur pc
SteliosKrom
SteliosKromOPā€¢2y ago
We will continue tomorrow bro bb I just tired a little bit with all of that When I will have free time we will continue
TheRanger
TheRangerā€¢2y ago
bye
SteliosKrom
SteliosKromOPā€¢2y ago
He, bro! I made highscore to show the highscore in the start of the game Now, I am gonna make it so that it will show for each difficulty the highscore I dont need any help right now if i will need i will tell oyu yoyu you Range need some help
SteliosKrom
SteliosKromOPā€¢2y ago
SteliosKrom
SteliosKromOPā€¢2y ago
In game manager it says that in line 124
SteliosKrom
SteliosKromOPā€¢2y ago
SteliosKrom
SteliosKromOPā€¢2y ago
this one
JakenVeina
JakenVeinaā€¢2y ago
what says what in line 124?
SteliosKrom
SteliosKromOPā€¢2y ago
menu screen.gameobjects.setactive it is that in the screenshot i send you @ReactiveVeina Do you have anything to say about that message? here @TheRanger I change something in LoadHighScore() and in DifficultyForEach() and check my code right now how it looks, but I still got a problem with saving my highscore for each difficulty. I already fixed the problem that my highscore was 0 at the start of the game. Now, for each button when i click and play it saves the highscore.
public void StartGame(Difficulties difficulty)
{
if (PlayerPrefs.HasKey("highScore"))
{
highScore = PlayerPrefs.GetInt("highScore", highScore);
Debug.Log("Value is: " + highScore);
}

isGameActive = true;
StartCoroutine(SpawnTarget());
UpdateScore(0);
DifficultiesForEach(difficulty);
menuScreen.gameObject.SetActive(false);
Debug.Log("The game started!");
}

public void LoadHighScoreOnStartGame(Difficulties difficulty)
{
highScore = PlayerPrefs.GetInt("highScore", highScore);
UpdateHighScore();
Debug.Log("Highscore loads on start!");
}

public void DifficultiesForEach(Difficulties difficulty)
{
if (difficulty == Difficulties.Easy && !isClicked)
{
isClicked = true;
spawnRate = 1.0f;
LoadHighScoreOnStartGame(difficulty);
Debug.Log("The button easy was clicked!");
}

else if (difficulty == Difficulties.Medium && !isClicked)
{
isClicked = true;
spawnRate = 0.7f;
LoadHighScoreOnStartGame(difficulty);
Debug.Log("The button medium was clicked!");
}

else if (difficulty == Difficulties.Hard && !isClicked)
{
isClicked = true;
spawnRate = 0.2f;
LoadHighScoreOnStartGame(difficulty);
Debug.Log("The button hard was clicked!");
}

}

}
public void StartGame(Difficulties difficulty)
{
if (PlayerPrefs.HasKey("highScore"))
{
highScore = PlayerPrefs.GetInt("highScore", highScore);
Debug.Log("Value is: " + highScore);
}

isGameActive = true;
StartCoroutine(SpawnTarget());
UpdateScore(0);
DifficultiesForEach(difficulty);
menuScreen.gameObject.SetActive(false);
Debug.Log("The game started!");
}

public void LoadHighScoreOnStartGame(Difficulties difficulty)
{
highScore = PlayerPrefs.GetInt("highScore", highScore);
UpdateHighScore();
Debug.Log("Highscore loads on start!");
}

public void DifficultiesForEach(Difficulties difficulty)
{
if (difficulty == Difficulties.Easy && !isClicked)
{
isClicked = true;
spawnRate = 1.0f;
LoadHighScoreOnStartGame(difficulty);
Debug.Log("The button easy was clicked!");
}

else if (difficulty == Difficulties.Medium && !isClicked)
{
isClicked = true;
spawnRate = 0.7f;
LoadHighScoreOnStartGame(difficulty);
Debug.Log("The button medium was clicked!");
}

else if (difficulty == Difficulties.Hard && !isClicked)
{
isClicked = true;
spawnRate = 0.2f;
LoadHighScoreOnStartGame(difficulty);
Debug.Log("The button hard was clicked!");
}

}

}
Check that with startgame(), LoadHighScore() and DifficultyForEach()
JakenVeina
JakenVeinaā€¢2y ago
Yes, I saw. What is your question about that?
SteliosKrom
SteliosKromOPā€¢2y ago
I don't understand what that means? It says that it is redundant
JakenVeina
JakenVeinaā€¢2y ago
what what means? what says that what is redundant?
SteliosKrom
SteliosKromOPā€¢2y ago
I don't understand why it says that? Check Here For that
JakenVeina
JakenVeinaā€¢2y ago
why what says what? you sent a screenshot showing a line of code, yes you've linked it to me multiple times I've seen it it doesn't "say" anything
SteliosKrom
SteliosKromOPā€¢2y ago
multiple times?
JakenVeina
JakenVeinaā€¢2y ago
it's a line of code
SteliosKrom
SteliosKromOPā€¢2y ago
yes check the message
JakenVeina
JakenVeinaā€¢2y ago
what is your question about that line of code?
SteliosKrom
SteliosKromOPā€¢2y ago
it says that this line of code is redundant
JakenVeina
JakenVeinaā€¢2y ago
what does?
SteliosKrom
SteliosKromOPā€¢2y ago
indirection is redundarnt redundant about this line of code
JakenVeina
JakenVeinaā€¢2y ago
what says that?
SteliosKrom
SteliosKromOPā€¢2y ago
I solve the problem myself. I just find what was the problme problem menuscreen.setactive(false) i don't need gameobject
JakenVeina
JakenVeinaā€¢2y ago
k
SteliosKrom
SteliosKromOPā€¢2y ago
game object is redundant What do you have to say about my problem with difficulties? I am clicking every difficulty easy, medium and hard and what i see is that it saves the highscore in each difficulty but it is the same for each the game starts with score to be 0 and highscore
SteliosKrom
SteliosKromOPā€¢2y ago
BlazeBin - eazlgjkqziix
A tool for sharing your source code with the world!
SteliosKrom
SteliosKromOPā€¢2y ago
Here is the script of game manager
JakenVeina
JakenVeinaā€¢2y ago
where is the code that saves the high score value?
SteliosKrom
SteliosKromOPā€¢2y ago
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class DifficultyButton : MonoBehaviour
{
public Difficulties difficulty;
private Button button;
private GameManager gameManager;

// Start is called before the first frame update
void Start()
{
button = GetComponent<Button>();
gameManager = GameObject.Find("GameManager").GetComponent<GameManager>();
button.onClick.AddListener(SetDifficulty);
}

void SetDifficulty()
{
Debug.Log(button.gameObject.name + " was clicked");
gameManager.StartGame(difficulty);
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class DifficultyButton : MonoBehaviour
{
public Difficulties difficulty;
private Button button;
private GameManager gameManager;

// Start is called before the first frame update
void Start()
{
button = GetComponent<Button>();
gameManager = GameObject.Find("GameManager").GetComponent<GameManager>();
button.onClick.AddListener(SetDifficulty);
}

void SetDifficulty()
{
Debug.Log(button.gameObject.name + " was clicked");
gameManager.StartGame(difficulty);
}
Here i have my difficultybutton script wait Check game manager There is a method i have that saves the highscore
SteliosKrom
SteliosKromOPā€¢2y ago
BlazeBin - zivsciytsbhy
A tool for sharing your source code with the world!
SteliosKrom
SteliosKromOPā€¢2y ago
Here is also another script where the game gets over then it saves highscore and all of that happen
JakenVeina
JakenVeinaā€¢2y ago
so, StartGame() is what loads the high scores?
SteliosKrom
SteliosKromOPā€¢2y ago
yes it is
JakenVeina
JakenVeinaā€¢2y ago
great
SteliosKrom
SteliosKromOPā€¢2y ago
Startgame() loads it
JakenVeina
JakenVeinaā€¢2y ago
where is the code that saves the high scores?
SteliosKrom
SteliosKromOPā€¢2y ago
Give me a minute
TheRanger
TheRangerā€¢2y ago
ive been summoned ur LoadHighScoreOnStartGame method is only loading highscore from ur disk without knowing which difficulty is chosen
SteliosKrom
SteliosKromOPā€¢2y ago
public void CheckSaveHighScore()
{
if (score > highScore)
{
highScore = score;
PlayerPrefs.SetInt("highScore", highScore);
PlayerPrefs.Save();
Debug.Log("HighScore was checked and saved!");
}
highScoreText.text = highScore.ToString();
}
public void CheckSaveHighScore()
{
if (score > highScore)
{
highScore = score;
PlayerPrefs.SetInt("highScore", highScore);
PlayerPrefs.Save();
Debug.Log("HighScore was checked and saved!");
}
highScoreText.text = highScore.ToString();
}
So, this is the code that saves highscore on game over in the other script I have sent called target script Here is also the UpdateHighScore() where it updates the highscore at the start of the game and at the game over it display the highscore.
public void UpdateHighScore()
{
highScoreText.text = "HighScore: " + highScore;
Debug.Log("HighScore updates");
}
public void UpdateHighScore()
{
highScoreText.text = "HighScore: " + highScore;
Debug.Log("HighScore updates");
}
JakenVeina
JakenVeinaā€¢2y ago
so, PlayerPerfs.Save()
TheRanger
TheRangerā€¢2y ago
finish the LoadHighScoreOnStartGame method first
JakenVeina
JakenVeinaā€¢2y ago
go with what he says, he's read into this already
SteliosKrom
SteliosKromOPā€¢2y ago
oh, I think I know what to do. You give me an idea, gotta try if it works Hey, wanna help me with the game? I did some changes some more changes in my code and actually in LoadHighScore()
TheRanger
TheRangerā€¢2y ago
what kind of changes?
SteliosKrom
SteliosKromOPā€¢2y ago
Check but I still cant do it my mind doesn't know how to solve this problem, I am not skilled enough maybe.
TheRanger
TheRangerā€¢2y ago
show what you did atleast
SteliosKrom
SteliosKromOPā€¢2y ago
public void LoadHighScoreOnStartGame(Difficulties difficulty)
{
if (difficulty == Difficulties.Easy && !isClicked)
{
isClicked = true;
highScore = PlayerPrefs.GetInt("highScore", highScore);
UpdateHighScore(highScore);
Debug.Log("Highscore loads on start!");
}

else if (difficulty == Difficulties.Medium && !isClicked)
{
isClicked = true;
highScore = PlayerPrefs.GetInt("highScore", highScore);
UpdateHighScore(highScore);
Debug.Log("Highscore loads on start!");
}

else if (difficulty == Difficulties.Hard && !isClicked)
{
isClicked = true;
highScore = PlayerPrefs.GetInt("highScore", highScore);
UpdateHighScore(highScore);
Debug.Log("Highscore loads on start!");
}

}

public void DifficultiesForEach(Difficulties difficulty)
{
if (difficulty == Difficulties.Easy && !isClicked)
{
isClicked = true;
spawnRate = 1.0f;
Debug.Log("The button easy was clicked!");
}

else if (difficulty == Difficulties.Medium && !isClicked)
{
isClicked = true;
spawnRate = 0.7f;
Debug.Log("The button medium was clicked!");
}

else if (difficulty == Difficulties.Hard && !isClicked)
{
isClicked = true;
spawnRate = 0.5f;
Debug.Log("The button hard was clicked!");
}

}

}
public void LoadHighScoreOnStartGame(Difficulties difficulty)
{
if (difficulty == Difficulties.Easy && !isClicked)
{
isClicked = true;
highScore = PlayerPrefs.GetInt("highScore", highScore);
UpdateHighScore(highScore);
Debug.Log("Highscore loads on start!");
}

else if (difficulty == Difficulties.Medium && !isClicked)
{
isClicked = true;
highScore = PlayerPrefs.GetInt("highScore", highScore);
UpdateHighScore(highScore);
Debug.Log("Highscore loads on start!");
}

else if (difficulty == Difficulties.Hard && !isClicked)
{
isClicked = true;
highScore = PlayerPrefs.GetInt("highScore", highScore);
UpdateHighScore(highScore);
Debug.Log("Highscore loads on start!");
}

}

public void DifficultiesForEach(Difficulties difficulty)
{
if (difficulty == Difficulties.Easy && !isClicked)
{
isClicked = true;
spawnRate = 1.0f;
Debug.Log("The button easy was clicked!");
}

else if (difficulty == Difficulties.Medium && !isClicked)
{
isClicked = true;
spawnRate = 0.7f;
Debug.Log("The button medium was clicked!");
}

else if (difficulty == Difficulties.Hard && !isClicked)
{
isClicked = true;
spawnRate = 0.5f;
Debug.Log("The button hard was clicked!");
}

}

}
I have tried to communicate with DifficultyButton maybe I dont have to take that difficulty in game manager and take the other one from the other script
TheRanger
TheRangerā€¢2y ago
what does highScore = PlayerPrefs.GetInt("highScore", highScore); do, in ur mind?
SteliosKrom
SteliosKromOPā€¢2y ago
Ok In my mind, it gets the highscore and stores the highscore to variable highscore thats how I understand it
TheRanger
TheRangerā€¢2y ago
which highscore tho?
SteliosKrom
SteliosKromOPā€¢2y ago
The highscore that is saved That was saved
TheRanger
TheRangerā€¢2y ago
which one?
SteliosKrom
SteliosKromOPā€¢2y ago
When i did
TheRanger
TheRangerā€¢2y ago
u have easy, medium and hard highscores right?
SteliosKrom
SteliosKromOPā€¢2y ago
you mean variables?
TheRanger
TheRangerā€¢2y ago
no
SteliosKrom
SteliosKromOPā€¢2y ago
yes i have
TheRanger
TheRangerā€¢2y ago
each difficulty has its own highScore right?
SteliosKrom
SteliosKromOPā€¢2y ago
three highscore yes
TheRanger
TheRangerā€¢2y ago
how does it know which highScore difficulty to load from ur disk
SteliosKrom
SteliosKromOPā€¢2y ago
So, it doesn't actually. What I am thinking is for sure that I have to use an if statement and inside it to check which difficulty corresponds to each difficulty button and I check when it get clicked then I do save highscore and all of that happen
TheRanger
TheRangerā€¢2y ago
you already did use an if statement
SteliosKrom
SteliosKromOPā€¢2y ago
yes That's what I ve made acutally
TheRanger
TheRangerā€¢2y ago
u have highScore = PlayerPrefs.GetInt("highScore", highScore) in ur 3 if conditions all of them will load the same highScore for example if you got score 10,000 in hard mode then u restarted the game and played easy it will load 10,000 as the highscore
SteliosKrom
SteliosKromOPā€¢2y ago
yes That's what it does So, let me check
TheRanger
TheRangerā€¢2y ago
yes, u are only saving 1 single highscore in your disk, and all the bodies of ur if conditions load from that same single highscore
SteliosKrom
SteliosKromOPā€¢2y ago
What I did was to make three different variables and then i check in the if conditions when it is higher than the score then save it to highscore something like that I can just add three texts for highscore I can remove that highscore i have right now and make three highscore texts in my canvas with these variables i have made
TheRanger
TheRangerā€¢2y ago
3 different variables?
SteliosKrom
SteliosKromOPā€¢2y ago
yes
TheRanger
TheRangerā€¢2y ago
can u show
SteliosKrom
SteliosKromOPā€¢2y ago
I can do that
TheRanger
TheRangerā€¢2y ago
three highscore texts? are u trying to display the 3 at the same time?
SteliosKrom
SteliosKromOPā€¢2y ago
no You didn't understand
TheRanger
TheRangerā€¢2y ago
then why did you make three highscore texts?
SteliosKrom
SteliosKromOPā€¢2y ago
I didn't make I am just thinking to make
TheRanger
TheRangerā€¢2y ago
ok, why?
SteliosKrom
SteliosKromOPā€¢2y ago
I will make three checksavemethods for these variables
TheRanger
TheRangerā€¢2y ago
ok lets talk about the 3 variables first, can u show it?
SteliosKrom
SteliosKromOPā€¢2y ago
public void CheckSaveHighScore()
{
if (score > highScore)
{
highScore = score;
PlayerPrefs.SetInt("highScore", highScore);
Debug.Log("HighScore was checked and saved!");
}
highScoreText.text = highScore.ToString();
}

public void CheckSaveHighScoreEasy()
{

}

public void CheckSaveHighScoreMedium()
{

}

public void CheckSaveHighScoreHard()
{

}
public void CheckSaveHighScore()
{
if (score > highScore)
{
highScore = score;
PlayerPrefs.SetInt("highScore", highScore);
Debug.Log("HighScore was checked and saved!");
}
highScoreText.text = highScore.ToString();
}

public void CheckSaveHighScoreEasy()
{

}

public void CheckSaveHighScoreMedium()
{

}

public void CheckSaveHighScoreHard()
{

}
So, like you see in checksavehighscore I ve made three more methods
TheRanger
TheRangerā€¢2y ago
those are methods not variables
SteliosKrom
SteliosKromOPā€¢2y ago
Yes i have also variables that i will use
public int highScoreEasy;
public int highScoreMedium;
public int highScoreHard;
public int highScoreEasy;
public int highScoreMedium;
public int highScoreHard;
I have also these variables that i will use in these methods I wanna remove the first method
TheRanger
TheRangerā€¢2y ago
no need to do the 3 variables 1 is enough
SteliosKrom
SteliosKromOPā€¢2y ago
and just check save the highscore with the other three methods i ve made
TheRanger
TheRangerā€¢2y ago
u have no reason to load the 3 highscores into the memory
SteliosKrom
SteliosKromOPā€¢2y ago
ok
TheRanger
TheRangerā€¢2y ago
only load what is needed
SteliosKrom
SteliosKromOPā€¢2y ago
So, I still didn't find the problem. I know like you said it is in the loadhighscore method because I am using player prefs in every if condition the same highscore for every difficulty I set int and then get the highscore the same highscore from it
TheRanger
TheRangerā€¢2y ago
a video game doesn't load all of the levels in the game when u are only playing the selected level waste of memory
SteliosKrom
SteliosKromOPā€¢2y ago
I know
TheRanger
TheRangerā€¢2y ago
it only loads the selected level same with highscore, u only load one of the three like ur highScoreText u dont have highScoreTextEasy, highScoreTextMedium, highScoreTextHard right?
SteliosKrom
SteliosKromOPā€¢2y ago
yes Thats why I wanted to make three variables
TheRanger
TheRangerā€¢2y ago
wrong
SteliosKrom
SteliosKromOPā€¢2y ago
I need three texts?
TheRanger
TheRangerā€¢2y ago
no,
SteliosKrom
SteliosKromOPā€¢2y ago
I dont think so
TheRanger
TheRangerā€¢2y ago
same with the variable you only need one
SteliosKrom
SteliosKromOPā€¢2y ago
I just have to use it outside of the if conditions and once? I don't have to use them in every if condition? the player prefs i mean
TheRanger
TheRangerā€¢2y ago
you do, but you have to specify which data to load
SteliosKrom
SteliosKromOPā€¢2y ago
I am thinking when i use player prefs in conditions that it does everything separately but it doesn't actually works like that. It loads the same highscore for every diff
TheRanger
TheRangerā€¢2y ago
ud have something like that
public void LoadHighScoreOnStartGame(Difficulties difficulty)
{
if (difficulty == Difficulties.Easy)
{
highScore = PlayerPrefs.GetInt("highScore_Easy");
Debug.Log("Highscore Easy loads on start!");
}

else if (difficulty == Difficulties.Medium)
{
highScore = PlayerPrefs.GetInt("highScore_Medium");
Debug.Log("Highscore Medium loads on start!");
}

else if (difficulty == Difficulties.Hard)
{
highScore = PlayerPrefs.GetInt("highScore_Hard");
Debug.Log("Highscore Hard loads on start!");
}
UpdateHighScore(highScore);
}
public void LoadHighScoreOnStartGame(Difficulties difficulty)
{
if (difficulty == Difficulties.Easy)
{
highScore = PlayerPrefs.GetInt("highScore_Easy");
Debug.Log("Highscore Easy loads on start!");
}

else if (difficulty == Difficulties.Medium)
{
highScore = PlayerPrefs.GetInt("highScore_Medium");
Debug.Log("Highscore Medium loads on start!");
}

else if (difficulty == Difficulties.Hard)
{
highScore = PlayerPrefs.GetInt("highScore_Hard");
Debug.Log("Highscore Hard loads on start!");
}
UpdateHighScore(highScore);
}
SteliosKrom
SteliosKromOPā€¢2y ago
no I have highscore variable a single one for every diff oh wait
TheRanger
TheRangerā€¢2y ago
you dont need to load only whats needed if ur playing on easy, no need to load the medium and hard difficulty highscore
SteliosKrom
SteliosKromOPā€¢2y ago
oh so i actually dont need the variable highscore next to GetInt("highScore")?
TheRanger
TheRangerā€¢2y ago
the 2nd parameter is the default value that it returns if it couldnt find the specified data in ur pc
SteliosKrom
SteliosKromOPā€¢2y ago
the second parameter in dfficulty button you mean?
TheRanger
TheRangerā€¢2y ago
in the GetInt method say u did highScore = PlayerPrefs.GetInt("highScore_Easy",500); if highScore_Easy data wasnt saved in ur computer highScore's value will be 500
SteliosKrom
SteliosKromOPā€¢2y ago
yes so when I use set int I basically save that data in my computer and if I don't use get int then I will never retrieve that data that was saved right?
TheRanger
TheRangerā€¢2y ago
yes
SteliosKrom
SteliosKromOPā€¢2y ago
public void LoadHighScoreOnStartGame(Difficulties difficulty)
{

if (difficulty == Difficulties.Easy && !isClicked)
{
isClicked = true;
highScore = PlayerPrefs.GetInt("highScore", highScore);
UpdateHighScore();
Debug.Log("Highscore loads on start!");
}

else if (difficulty == Difficulties.Medium && !isClicked)
{
isClicked = true;
highScore = PlayerPrefs.GetInt("highScore", highScore);
UpdateHighScore();
Debug.Log("Highscore loads on start!");
}

else if (difficulty == Difficulties.Hard && !isClicked)
{
isClicked = true;
highScore = PlayerPrefs.GetInt("highScore", highScore);
UpdateHighScore();
Debug.Log("Highscore loads on start!");
}
public void LoadHighScoreOnStartGame(Difficulties difficulty)
{

if (difficulty == Difficulties.Easy && !isClicked)
{
isClicked = true;
highScore = PlayerPrefs.GetInt("highScore", highScore);
UpdateHighScore();
Debug.Log("Highscore loads on start!");
}

else if (difficulty == Difficulties.Medium && !isClicked)
{
isClicked = true;
highScore = PlayerPrefs.GetInt("highScore", highScore);
UpdateHighScore();
Debug.Log("Highscore loads on start!");
}

else if (difficulty == Difficulties.Hard && !isClicked)
{
isClicked = true;
highScore = PlayerPrefs.GetInt("highScore", highScore);
UpdateHighScore();
Debug.Log("Highscore loads on start!");
}
You said above about my code. I have it like that
TheRanger
TheRangerā€¢2y ago
highScore = PlayerPrefs.GetInt("highScore", highScore);
SteliosKrom
SteliosKromOPā€¢2y ago
I actually don't need the isclicked bool so I removed it in this method
TheRanger
TheRangerā€¢2y ago
is the same for each difficulty
SteliosKrom
SteliosKromOPā€¢2y ago
yes
TheRanger
TheRangerā€¢2y ago
so it wont differentiate the highscores
SteliosKrom
SteliosKromOPā€¢2y ago
Up there you made some changes in the string inside player prefs you did
"highScoreEasy" highScoreMed" highScoreHard"
"highScoreEasy" highScoreMed" highScoreHard"
TheRanger
TheRangerā€¢2y ago
yup thats the correct way, PlayerPrefs there knows which HighScore to load depending on the difficulty
SteliosKrom
SteliosKromOPā€¢2y ago
in player prefs without the int value nexto it next to it oh really
TheRanger
TheRangerā€¢2y ago
yeah if the key highScoreEasy wasnt saved in ur computer 0 will be returned
SteliosKrom
SteliosKromOPā€¢2y ago
You have used UpdateHighScore() outside of the conditions why you did that?
TheRanger
TheRangerā€¢2y ago
because it will get called anyway and will update the highscore
SteliosKrom
SteliosKromOPā€¢2y ago
ok
TheRanger
TheRangerā€¢2y ago
the cleaner the code the better programmer u are
SteliosKrom
SteliosKromOPā€¢2y ago
But I could have the UpdateHighScore() inside the conditions right? It wasn't a problem I mean?
TheRanger
TheRangerā€¢2y ago
yeah but still, make ur code cleaner
SteliosKrom
SteliosKromOPā€¢2y ago
Can you please explain to me what that code does?
TheRanger
TheRangerā€¢2y ago
what code?
SteliosKrom
SteliosKromOPā€¢2y ago
if (PlayerPrefs.HasKey("highScore"))
{
highScore = PlayerPrefs.GetInt("highScore", highScore);
Debug.Log("Value is: " + highScore);
}
if (PlayerPrefs.HasKey("highScore"))
{
highScore = PlayerPrefs.GetInt("highScore", highScore);
Debug.Log("Value is: " + highScore);
}
I got confused especially with this block of code. When we use haskey? Why we use it?
TheRanger
TheRangerā€¢2y ago
to check if highScore data is saved in ur pc
SteliosKrom
SteliosKromOPā€¢2y ago
Don't we do that with that
public void CheckSaveHighScore()
{
if (score > highScore)
{
highScore = score;
PlayerPrefs.SetInt("highScore", highScore);
Debug.Log("HighScore was checked and saved!");
}
highScoreText.text = highScore.ToString();
}
public void CheckSaveHighScore()
{
if (score > highScore)
{
highScore = score;
PlayerPrefs.SetInt("highScore", highScore);
Debug.Log("HighScore was checked and saved!");
}
highScoreText.text = highScore.ToString();
}
TheRanger
TheRangerā€¢2y ago
no, ur saving the highscore there
SteliosKrom
SteliosKromOPā€¢2y ago
I don't check it?
TheRanger
TheRangerā€¢2y ago
u are not checking if highScore data is stored in ur pc there
SteliosKrom
SteliosKromOPā€¢2y ago
I am just checking the values of the variables or what?
TheRanger
TheRangerā€¢2y ago
in if (score > highScore) yes
SteliosKrom
SteliosKromOPā€¢2y ago
So it has a difference when I check values of variables and those values on my pc ?
TheRanger
TheRangerā€¢2y ago
values of variables is what is stored in ur current game
SteliosKrom
SteliosKromOPā€¢2y ago
yes
TheRanger
TheRangerā€¢2y ago
PlayerPrefs is what is stored in your computer, your hard disk in a file somewhere
SteliosKrom
SteliosKromOPā€¢2y ago
Oh it is more understandable right now
TheRanger
TheRangerā€¢2y ago
you can imagine a file looks like this
highScore_Easy: 5
highScore_Medium: 100
highScore_Hard: 500
highScore_Easy: 5
highScore_Medium: 100
highScore_Hard: 500
SteliosKrom
SteliosKromOPā€¢2y ago
yes So, that code actually saves the highscore somewhere in a file right?
if (PlayerPrefs.HasKey("highScore"))
{
highScore = PlayerPrefs.GetInt("highScore", highScore);
Debug.Log("Value is: " + highScore);
}
if (PlayerPrefs.HasKey("highScore"))
{
highScore = PlayerPrefs.GetInt("highScore", highScore);
Debug.Log("Value is: " + highScore);
}
TheRanger
TheRangerā€¢2y ago
no, it loads it GetInt loads, SetInt saves
SteliosKrom
SteliosKromOPā€¢2y ago
oh, ok
TheRanger
TheRangerā€¢2y ago
brb back
SteliosKrom
SteliosKromOPā€¢2y ago
I removed highscore next to string in player prefs in loadhighscore method but what happens is that in start game it starts with 0 in highscore I did something like you did
public void LoadHighScoreOnStartGame(Difficulties difficulty)
{

if (difficulty == Difficulties.Easy)
{
highScore = PlayerPrefs.GetInt("highScoreEasy");
Debug.Log("Easy highscore loads on start!");
}

else if (difficulty == Difficulties.Medium)
{
highScore = PlayerPrefs.GetInt("highScoreMedium");
Debug.Log("Medium highscore loads on start!");
}

else if (difficulty == Difficulties.Hard)
{
highScore = PlayerPrefs.GetInt("highScoreHard");
Debug.Log("Hard highscore loads on start!");
}
UpdateHighScore(highScore);
}
public void LoadHighScoreOnStartGame(Difficulties difficulty)
{

if (difficulty == Difficulties.Easy)
{
highScore = PlayerPrefs.GetInt("highScoreEasy");
Debug.Log("Easy highscore loads on start!");
}

else if (difficulty == Difficulties.Medium)
{
highScore = PlayerPrefs.GetInt("highScoreMedium");
Debug.Log("Medium highscore loads on start!");
}

else if (difficulty == Difficulties.Hard)
{
highScore = PlayerPrefs.GetInt("highScoreHard");
Debug.Log("Hard highscore loads on start!");
}
UpdateHighScore(highScore);
}
but with that highscore remains 0 in start game for every diff but it saves the highscore because i see in console that the values is 40 for example
TheRanger
TheRangerā€¢2y ago
ofcourse theyre 0 u never saved them in the first place
SteliosKrom
SteliosKromOPā€¢2y ago
But it works it saves every highscore separately for each diff like i see in console
TheRanger
TheRangerā€¢2y ago
and? when u restart the game
SteliosKrom
SteliosKromOPā€¢2y ago
when i restart everything goes to 0 and appears also in highscore text I will have to save it like you said
TheRanger
TheRangerā€¢2y ago
so highscore is 0 in text, right?
SteliosKrom
SteliosKromOPā€¢2y ago
yes when i restart and play again
TheRanger
TheRangerā€¢2y ago
well u need to save it how does the code that save the highscore look like?
SteliosKrom
SteliosKromOPā€¢2y ago
public void CheckSaveHighScore()
{
if (score > highScore)
{
highScore = score;
PlayerPrefs.SetInt("highScore", highScore);
Debug.Log("HighScore was checked and saved!");
}
highScoreText.text = highScore.ToString();
}
public void CheckSaveHighScore()
{
if (score > highScore)
{
highScore = score;
PlayerPrefs.SetInt("highScore", highScore);
Debug.Log("HighScore was checked and saved!");
}
highScoreText.text = highScore.ToString();
}
TheRanger
TheRangerā€¢2y ago
thats wrong
SteliosKrom
SteliosKromOPā€¢2y ago
Is it?
TheRanger
TheRangerā€¢2y ago
yes, u should see why
SteliosKrom
SteliosKromOPā€¢2y ago
ok
TheRanger
TheRangerā€¢2y ago
if u saved, u can imagine ur file will look like this
highScore: 100
highScore: 100
that highscore is neither for difficulty easy, or medium, or hard šŸ˜…
SteliosKrom
SteliosKromOPā€¢2y ago
I know why I don't know why for one moment I thought I could do it but no šŸ˜” You said that this highscore is neither for difficuly or any difficulty? You mean this highscore that I save in CheckSaveHighScore()?
TheRanger
TheRangerā€¢2y ago
yes it doesnt represent any of them if you start the game and pressed one of the difficulty buttons, the game will run this method say u chose Easy it will try to find the value of highScoreEasy in the playerPref's file but it couldn't find it because, only
highScore: 100
highScore: 100
is stored in the file
SteliosKrom
SteliosKromOPā€¢2y ago
Understood Check what I did
public void CheckSaveHighScore()
{
if (score > highScore && difficulty == Difficulties.Easy)
{
highScore = score;
PlayerPrefs.SetInt("highScoreEasy", highScore);
Debug.Log("HighScore was checked and saved!");
}

else if (score > highScore && difficulty == Difficulties.Medium)
{
highScore = score;
PlayerPrefs.SetInt("highScoreMedium", highScore);
Debug.Log("HighScore was checked and saved!");
}

else if (score > highScore && difficulty == Difficulties.Hard)
{
highScore = score;
PlayerPrefs.SetInt("highScoreHard", highScore);
Debug.Log("HighScore was checked and saved!");
}
highScoreText.text = highScore.ToString();
}
public void CheckSaveHighScore()
{
if (score > highScore && difficulty == Difficulties.Easy)
{
highScore = score;
PlayerPrefs.SetInt("highScoreEasy", highScore);
Debug.Log("HighScore was checked and saved!");
}

else if (score > highScore && difficulty == Difficulties.Medium)
{
highScore = score;
PlayerPrefs.SetInt("highScoreMedium", highScore);
Debug.Log("HighScore was checked and saved!");
}

else if (score > highScore && difficulty == Difficulties.Hard)
{
highScore = score;
PlayerPrefs.SetInt("highScoreHard", highScore);
Debug.Log("HighScore was checked and saved!");
}
highScoreText.text = highScore.ToString();
}
I did something like that but it doesn't work like I wanted
TheRanger
TheRangerā€¢2y ago
what do u mean? oh yea game doesnt know what difficulty ur on go back to the startgame method
TheRanger
TheRangerā€¢2y ago
see this variable other there
SteliosKrom
SteliosKromOPā€¢2y ago
oh
TheRanger
TheRangerā€¢2y ago
the GameManager's variable, field
SteliosKrom
SteliosKromOPā€¢2y ago
Yes i have it in game manager
TheRanger
TheRangerā€¢2y ago
you never set it
SteliosKrom
SteliosKromOPā€¢2y ago
What do you mean I ve set it ?
TheRanger
TheRangerā€¢2y ago
never set it you never assigned a value to it
SteliosKrom
SteliosKromOPā€¢2y ago
oh yes I know that Do i really have to assign a value? What values does it take?
TheRanger
TheRangerā€¢2y ago
you take the value from the argument difficulty in the StartGame method
SteliosKrom
SteliosKromOPā€¢2y ago
I got that argument
TheRanger
TheRangerā€¢2y ago
public void StartGame(Difficulties difficulty)
{
this.difficulty = difficulty;
.............. // rest of ur code
}
public void StartGame(Difficulties difficulty)
{
this.difficulty = difficulty;
.............. // rest of ur code
}
note why i put this keyword because the method has another variable called difficulty
SteliosKrom
SteliosKromOPā€¢2y ago
I dont know what
this
this
is actually I have never used it before and is there a difference between the parameter difficulty and field difficuly?
TheRanger
TheRangerā€¢2y ago
difficulty = difficulty; would just set a value to its own and we want to change the field one, not the parameter one
SteliosKrom
SteliosKromOPā€¢2y ago
I cant separate them I cant understnad the difference
TheRanger
TheRangerā€¢2y ago
big difference
SteliosKrom
SteliosKromOPā€¢2y ago
the parameter passes a value to another method or the main program but field what actually do ?
TheRanger
TheRangerā€¢2y ago
the field is a variable that belongs to the class not the method
SteliosKrom
SteliosKromOPā€¢2y ago
ok Yes i know that But for which purposes we use them?
TheRanger
TheRangerā€¢2y ago
to store data? when u run this
SteliosKrom
SteliosKromOPā€¢2y ago
Here I am using the field difficulty variable
TheRanger
TheRangerā€¢2y ago
it takes the difficulty field one
SteliosKrom
SteliosKromOPā€¢2y ago
Check
TheRanger
TheRangerā€¢2y ago
no need to add this because there is no parameter or local variable called difficulty in this method so C# automatically knows u are refering to the field one
SteliosKrom
SteliosKromOPā€¢2y ago
ok
TheRanger
TheRangerā€¢2y ago
but its optional, u can still add it
SteliosKrom
SteliosKromOPā€¢2y ago
Maybe I have to use the parameter and not the field in the checksave()? I am using the field in it and in loadhighscore the parameter diff
TheRanger
TheRangerā€¢2y ago
go ahead, but where would u get the value of the difficulty that u chose from? šŸ˜…
SteliosKrom
SteliosKromOPā€¢2y ago
Thats a good question XD. You said where I would get the value of difficulty that I chose from. What do you mean?
TheRanger
TheRangerā€¢2y ago
if u used the parameter and not the field in the checksave
SteliosKrom
SteliosKromOPā€¢2y ago
yes
TheRanger
TheRangerā€¢2y ago
where would you pass the value to the method from?
SteliosKrom
SteliosKromOPā€¢2y ago
I have some trouble to work with parameters, we have in school as well an assumed programming language and I have some difficulties in working with them sorry but I will try XD I ve added the parameter in checksavehighscore
public void CheckSaveHighScore(Difficulties difficulty)
{
if (score > highScore && difficulty == Difficulties.Easy)
{
highScore = score;
PlayerPrefs.SetInt("highScoreEasy", highScore);
Debug.Log("HighScore was checked and saved!");
}

else if (score > highScore && difficulty == Difficulties.Medium)
{
highScore = score;
PlayerPrefs.SetInt("highScoreMedium", highScore);
Debug.Log("HighScore was checked and saved!");
}

else if (score > highScore && difficulty == Difficulties.Hard)
{
highScore = score;
PlayerPrefs.SetInt("highScoreHard", highScore);
Debug.Log("HighScore was checked and saved!");
}
highScoreText.text = highScore.ToString();
}
public void CheckSaveHighScore(Difficulties difficulty)
{
if (score > highScore && difficulty == Difficulties.Easy)
{
highScore = score;
PlayerPrefs.SetInt("highScoreEasy", highScore);
Debug.Log("HighScore was checked and saved!");
}

else if (score > highScore && difficulty == Difficulties.Medium)
{
highScore = score;
PlayerPrefs.SetInt("highScoreMedium", highScore);
Debug.Log("HighScore was checked and saved!");
}

else if (score > highScore && difficulty == Difficulties.Hard)
{
highScore = score;
PlayerPrefs.SetInt("highScoreHard", highScore);
Debug.Log("HighScore was checked and saved!");
}
highScoreText.text = highScore.ToString();
}
now the difficulty is a parameter and not the field that was before
public class Target : MonoBehaviour
{

public ParticleSystem explosionParticle;
public int pointValue;
public Difficulties difficulty;

private Rigidbody targerRb;
private GameManager gameManager;
private float minSpeed = 12;
private float maxSpeed = 14;
private float minTorque = -10;
private float maxTorque = 10;
private float ySpawnPos = -2;
private float xRange = 4;
private float yRange = -10;
public class Target : MonoBehaviour
{

public ParticleSystem explosionParticle;
public int pointValue;
public Difficulties difficulty;

private Rigidbody targerRb;
private GameManager gameManager;
private float minSpeed = 12;
private float maxSpeed = 14;
private float minTorque = -10;
private float maxTorque = 10;
private float ySpawnPos = -2;
private float xRange = 4;
private float yRange = -10;
I ve added public difficulties difficulty in target script so that I can pass the value in the checksave highscore where i call it in destroy out of bounds method Where it goes game over if target is out of bound I don't know if that's correct but I am gonna try it
gameManager.CheckSaveHighScore(difficulty);
gameManager.CheckSaveHighScore(difficulty);
in that
public void DestroyGoodOutOfBounds()
{
if (transform.position.y < yRange && gameObject.CompareTag("Good") && gameManager.isGameActive)
{
gameManager.isGameActive = false;
Destroy(gameObject);
gameManager.GameOver();
gameManager.StopPlayerAudioOnGameOver();
gameManager.GameOverSoundOnGameOver();
gameManager.CheckSaveHighScore(difficulty);
gameManager.UpdateHighScore(gameManager.highScore);
Debug.Log("Good objects have been destroyed!");
}

}
public void DestroyGoodOutOfBounds()
{
if (transform.position.y < yRange && gameObject.CompareTag("Good") && gameManager.isGameActive)
{
gameManager.isGameActive = false;
Destroy(gameObject);
gameManager.GameOver();
gameManager.StopPlayerAudioOnGameOver();
gameManager.GameOverSoundOnGameOver();
gameManager.CheckSaveHighScore(difficulty);
gameManager.UpdateHighScore(gameManager.highScore);
Debug.Log("Good objects have been destroyed!");
}

}
In that sorry
TheRanger
TheRangerā€¢2y ago
why does target have a field called difficulty? it doesnt make sense for each target to have a difficulty value
SteliosKrom
SteliosKromOPā€¢2y ago
SteliosKrom
SteliosKromOPā€¢2y ago
Because it says that It doesnn't make sense why?
TheRanger
TheRangerā€¢2y ago
the game has a difficulty, not a target can each target have different difficulties in easy game mode?
SteliosKrom
SteliosKromOPā€¢2y ago
XD no
TheRanger
TheRangerā€¢2y ago
my point you dont need a parameter to the method when the class already has a field
SteliosKrom
SteliosKromOPā€¢2y ago
then why I am using parameter in checksave method?
TheRanger
TheRangerā€¢2y ago
ask yourself that
SteliosKrom
SteliosKromOPā€¢2y ago
Stelios why are you using the parameter? Ok, anyway I will sit and think again what am i doing wrong
MODiX
MODiXā€¢2y ago
TheRanger#3357
REPL Result: Success
int Sum(int a, int b)
{
return a + b;
}

Sum(2, 3)
int Sum(int a, int b)
{
return a + b;
}

Sum(2, 3)
Result: int
5
5
Compile: 534.390ms | Execution: 31.081ms | React with āŒ to remove this embed.
TheRanger
TheRangerā€¢2y ago
a parameter is just a variable that you pass when ur calling a method
SteliosKrom
SteliosKromOPā€¢2y ago
Oh, so i have to return a value if I am not mistaken
TheRanger
TheRangerā€¢2y ago
no
MODiX
MODiXā€¢2y ago
TheRanger#3357
REPL Result: Success
void Sum(int a, int b)
{
Console.WriteLine(a + b);
}

Sum(2, 3)
void Sum(int a, int b)
{
Console.WriteLine(a + b);
}

Sum(2, 3)
Console Output
5
5
Compile: 608.393ms | Execution: 33.619ms | React with āŒ to remove this embed.
TheRanger
TheRangerā€¢2y ago
point is, when u pass 2 and 3 when u called the sum method a's value became 2, b's value became 3 then u sum them
SteliosKrom
SteliosKromOPā€¢2y ago
Yes it does the sum i know that
TheRanger
TheRangerā€¢2y ago
then a and b gets deleted when method finishes its execution u really need to learn the basics before u even code unity ur just wasting time
SteliosKrom
SteliosKromOPā€¢2y ago
I have to I know but I have started very quickly this year because of exams like i said
TheRanger
TheRangerā€¢2y ago
continue later then
SteliosKrom
SteliosKromOPā€¢2y ago
I just want to finish this I cant leave it here.
TheRanger
TheRangerā€¢2y ago
why?
SteliosKrom
SteliosKromOPā€¢2y ago
I will have it in my mind that I didn't finished a certain task
TheRanger
TheRangerā€¢2y ago
reprogram ur brain finishing a task with cheating is not helpful it wont let you learn
SteliosKrom
SteliosKromOPā€¢2y ago
I know that šŸ™‚
TheRanger
TheRangerā€¢2y ago
learn to move on
SteliosKrom
SteliosKromOPā€¢2y ago
I don't cheat in school, for example when I write a test or something I am trying my best I have never cheated only when I was in high school
TheRanger
TheRangerā€¢2y ago
well now dont start cheating or it will become a habit that will really get be hard to get rid of
SteliosKrom
SteliosKromOPā€¢2y ago
I am not cheating XD Who ever told you that??
TheRanger
TheRangerā€¢2y ago
here i mean im just giving you code
SteliosKrom
SteliosKromOPā€¢2y ago
I didn't tell you to give me any answers, just some tips and maybe some hints like you did and do
TheRanger
TheRangerā€¢2y ago
thats not how i see it
SteliosKrom
SteliosKromOPā€¢2y ago
The basics of C# I have learned bro I haven't learned OOP in this programming language
TheRanger
TheRangerā€¢2y ago
not sure what basics mean to u
SteliosKrom
SteliosKromOPā€¢2y ago
I just started
TheRanger
TheRangerā€¢2y ago
OOP is one of the basics of C#
SteliosKrom
SteliosKromOPā€¢2y ago
Only functional programming i ve learned
TheRanger
TheRangerā€¢2y ago
so whats left to u in ur game?
SteliosKrom
SteliosKromOPā€¢2y ago
loops, if else statements, data types, data structures lists and more So, only the highscores to be saved in each difficulty
TheRanger
TheRangerā€¢2y ago
remove the parameter from CheckSaveHighScore method
SteliosKrom
SteliosKromOPā€¢2y ago
Can I ask why do i have to do that?
TheRanger
TheRangerā€¢2y ago
because you already have the difficulty field in the class
SteliosKrom
SteliosKromOPā€¢2y ago
Just give me an explantation oh ok You said in game manager to remove it? Or in target script?
TheRanger
TheRangerā€¢2y ago
the field? target script yeah
SteliosKrom
SteliosKromOPā€¢2y ago
I removed it it says no context
TheRanger
TheRangerā€¢2y ago
?
SteliosKrom
SteliosKromOPā€¢2y ago
no argument sorry
TheRanger
TheRangerā€¢2y ago
well thats normal it doesnt exist anymore
SteliosKrom
SteliosKromOPā€¢2y ago
SteliosKrom
SteliosKromOPā€¢2y ago
this
TheRanger
TheRangerā€¢2y ago
i did say this seems u dont read all of my messages
SteliosKrom
SteliosKromOPā€¢2y ago
I read no I told you in game manager or target you said target
TheRanger
TheRangerā€¢2y ago
what u removed there is the argument parameter is where it sits in the definition of the method
SteliosKrom
SteliosKromOPā€¢2y ago
so in game manager
TheRanger
TheRangerā€¢2y ago
public void CheckSaveHighScore()
SteliosKrom
SteliosKromOPā€¢2y ago
it is in game manager
TheRanger
TheRangerā€¢2y ago
was talking about the field
SteliosKrom
SteliosKromOPā€¢2y ago
ok I did that
TheRanger
TheRangerā€¢2y ago
how does CheckSaveHighScore method and StartGame method look like now?
SteliosKrom
SteliosKromOPā€¢2y ago
public void CheckSaveHighScore(Difficulties difficulty)
{
if (score > highScore && difficulty == Difficulties.Easy)
{
highScore = score;
PlayerPrefs.SetInt("highScoreEasy", highScore);
Debug.Log("HighScore was checked and saved!");
}

else if (score > highScore && difficulty == Difficulties.Medium)
{
highScore = score;
PlayerPrefs.SetInt("highScoreMedium", highScore);
Debug.Log("HighScore was checked and saved!");
}

else if (score > highScore && difficulty == Difficulties.Hard)
{
highScore = score;
PlayerPrefs.SetInt("highScoreHard", highScore);
Debug.Log("HighScore was checked and saved!");
}
highScoreText.text = highScore.ToString();
}
public void CheckSaveHighScore(Difficulties difficulty)
{
if (score > highScore && difficulty == Difficulties.Easy)
{
highScore = score;
PlayerPrefs.SetInt("highScoreEasy", highScore);
Debug.Log("HighScore was checked and saved!");
}

else if (score > highScore && difficulty == Difficulties.Medium)
{
highScore = score;
PlayerPrefs.SetInt("highScoreMedium", highScore);
Debug.Log("HighScore was checked and saved!");
}

else if (score > highScore && difficulty == Difficulties.Hard)
{
highScore = score;
PlayerPrefs.SetInt("highScoreHard", highScore);
Debug.Log("HighScore was checked and saved!");
}
highScoreText.text = highScore.ToString();
}
public void StartGame(Difficulties difficulty)
{
if (PlayerPrefs.HasKey("highScore"))
{
highScore = PlayerPrefs.GetInt("highScore", highScore);
Debug.Log("Value is: " + highScore);
}

isGameActive = true;
StartCoroutine(SpawnTarget());
UpdateScore(0);
UpdateHighScore(highScore);
DifficultiesForEach(difficulty);
LoadHighScoreOnStartGame(difficulty);
menuScreen.SetActive(false);
Debug.Log("The game started!");
}
public void StartGame(Difficulties difficulty)
{
if (PlayerPrefs.HasKey("highScore"))
{
highScore = PlayerPrefs.GetInt("highScore", highScore);
Debug.Log("Value is: " + highScore);
}

isGameActive = true;
StartCoroutine(SpawnTarget());
UpdateScore(0);
UpdateHighScore(highScore);
DifficultiesForEach(difficulty);
LoadHighScoreOnStartGame(difficulty);
menuScreen.SetActive(false);
Debug.Log("The game started!");
}
TheRanger
TheRangerā€¢2y ago
replace public void CheckSaveHighScore(Difficulties difficulty) with public void CheckSaveHighScore() u forgot to add this.difficulty in StartGame like i mentioned earlier
SteliosKrom
SteliosKromOPā€¢2y ago
You said that i dont have to
TheRanger
TheRangerā€¢2y ago
where?
SteliosKrom
SteliosKromOPā€¢2y ago
here
TheRanger
TheRangerā€¢2y ago
that was for CheckSaveHighScore not StartGame
SteliosKrom
SteliosKromOPā€¢2y ago
ok so i have to add in start game this.difficulty
TheRanger
TheRangerā€¢2y ago
public void StartGame(Difficulties difficulty)
{
this.difficulty = difficulty;

isGameActive = true;
StartCoroutine(SpawnTarget());
UpdateScore(0);
UpdateHighScore(highScore);
DifficultiesForEach(difficulty);
LoadHighScoreOnStartGame(difficulty);
menuScreen.SetActive(false);
Debug.Log("The game started!");
}
public void StartGame(Difficulties difficulty)
{
this.difficulty = difficulty;

isGameActive = true;
StartCoroutine(SpawnTarget());
UpdateScore(0);
UpdateHighScore(highScore);
DifficultiesForEach(difficulty);
LoadHighScoreOnStartGame(difficulty);
menuScreen.SetActive(false);
Debug.Log("The game started!");
}
SteliosKrom
SteliosKromOPā€¢2y ago
this.difficulty what actually do?
TheRanger
TheRangerā€¢2y ago
pretty sure i said earlier, it refers to the field difficulty instead
SteliosKrom
SteliosKromOPā€¢2y ago
ok I don't need the playerprefs.has key in if condition in start game?
TheRanger
TheRangerā€¢2y ago
do u know what it does?
SteliosKrom
SteliosKromOPā€¢2y ago
It loads the highscore in the start of the game if its true
TheRanger
TheRangerā€¢2y ago
yes but which highscore? easy or medium or hard?
SteliosKrom
SteliosKromOPā€¢2y ago
that which is in the loadhighscore method that I call it in start game so when difficulty is difficulty.easy then it loads the highscore of the current difficulty
TheRanger
TheRangerā€¢2y ago
?? forget that im asking u what
if (PlayerPrefs.HasKey("highScore"))
{
highScore = PlayerPrefs.GetInt("highScore", highScore);
Debug.Log("Value is: " + highScore);
}
if (PlayerPrefs.HasKey("highScore"))
{
highScore = PlayerPrefs.GetInt("highScore", highScore);
Debug.Log("Value is: " + highScore);
}
does
SteliosKrom
SteliosKromOPā€¢2y ago
I told you
TheRanger
TheRangerā€¢2y ago
forget the code around it pretend loadhighscore doesnt exist this piece of code is not in the loadhighscore method its in StartGame
SteliosKrom
SteliosKromOPā€¢2y ago
It says in haskey that it returns true if the given key exists in player prefs but which of player prefs i dont know
TheRanger
TheRangerā€¢2y ago
and why do u need it?
SteliosKrom
SteliosKromOPā€¢2y ago
So, I dont need it for that reason right? I dont have an existing key that is in player prefs there?
TheRanger
TheRangerā€¢2y ago
you never saved highScore in ur player prefs file u only save highScoreEasy, highScoreMedium, and highScoreHard
SteliosKrom
SteliosKromOPā€¢2y ago
in which method you say that I didn't saved highscore
TheRanger
TheRangerā€¢2y ago
in the checksavehighscore so just delete this part, u dont need it + u are already loading the highscore from the loadhighscore method
SteliosKrom
SteliosKromOPā€¢2y ago
ok i did a change
public void CheckSaveHighScore()
{
if (score > highScore)
{
highScore = score;
PlayerPrefs.SetInt("highScore", highScore);
Debug.Log("HighScore was checked and saved!");
}

else if (score > highScore && difficulty == Difficulties.Easy)
{
highScore = score;
PlayerPrefs.SetInt("highScoreEasy", highScore);
Debug.Log("HighScore was checked and saved!");
}

else if (score > highScore && difficulty == Difficulties.Medium)
{
highScore = score;
PlayerPrefs.SetInt("highScoreMedium", highScore);
Debug.Log("HighScore was checked and saved!");
}

else if (score > highScore && difficulty == Difficulties.Hard)
{
highScore = score;
PlayerPrefs.SetInt("highScoreHard", highScore);
Debug.Log("HighScore was checked and saved!");
}
highScoreText.text = highScore.ToString();
}
public void CheckSaveHighScore()
{
if (score > highScore)
{
highScore = score;
PlayerPrefs.SetInt("highScore", highScore);
Debug.Log("HighScore was checked and saved!");
}

else if (score > highScore && difficulty == Difficulties.Easy)
{
highScore = score;
PlayerPrefs.SetInt("highScoreEasy", highScore);
Debug.Log("HighScore was checked and saved!");
}

else if (score > highScore && difficulty == Difficulties.Medium)
{
highScore = score;
PlayerPrefs.SetInt("highScoreMedium", highScore);
Debug.Log("HighScore was checked and saved!");
}

else if (score > highScore && difficulty == Difficulties.Hard)
{
highScore = score;
PlayerPrefs.SetInt("highScoreHard", highScore);
Debug.Log("HighScore was checked and saved!");
}
highScoreText.text = highScore.ToString();
}
I ve added highscore that i forget like you said
TheRanger
TheRangerā€¢2y ago
this
if (score > highScore)
{
highScore = score;
PlayerPrefs.SetInt("highScore", highScore);
Debug.Log("HighScore was checked and saved!");
}
if (score > highScore)
{
highScore = score;
PlayerPrefs.SetInt("highScore", highScore);
Debug.Log("HighScore was checked and saved!");
}
for which difficulty? delete it ur saving a highscore that has no difficulty, which is pointless
SteliosKrom
SteliosKromOPā€¢2y ago
ok You said i have a highscore there that is never saved
TheRanger
TheRangerā€¢2y ago
yes?
SteliosKrom
SteliosKromOPā€¢2y ago
I dont see a highscore that is never saved, at least I cant notice it highscore saved to highscore easy hgishcore saved to highscore mid and hard as well I did it bro It works I just test the game it works like I wanted There is nothing missing like you said Let me check again and confirm that Yes it works In easy it saves the highscore so i did 265 it save that
TheRanger
TheRangerā€¢2y ago
dont start a task again until u learn the basics first
SteliosKrom
SteliosKromOPā€¢2y ago
in mid i did 240 it save that when i restart it is the same so every highscore in each difficulty is different I am not gonna start any task again I am going off till 12 june so thanks for the help you gave me, I learned something from you i think. For example how to use player prefs I understood the logic of how they save and how the load highscore for example. I still need like you said practice in basics of OOP in C# and also the basics in functional programming for example data structures, data types, for loops, while loops, break, continue and all of that. This summer I am gonna work with C# and Game Dev 5-6 hours per day that's my goal for this summer, so that when I will start college I will be ready. Do you have to say anything about that?? Can you close this thread?
TheRanger
TheRangerā€¢2y ago
sure
Want results from more Discord servers?
Add your server