Ants0li
November 29, 2014, 12:08pm
1
Hello everybody! I have a big problem.
So, my main task is to change speed of my char if score equals to 100.
So i have few scripts for it.
First of all im sending scores to my movement script
void OnDisable()
{
PlayerPrefs.SetInt ("Score", (int)playerScore);
}
Then im taking scores in my movement script and creating if statement, that if scores equals to 100 speed will become +1 from original speed ( its equals to 3.0f)
void increasespeed()
{
score = PlayerPrefs.GetInt ("Score") * 10;
if((int)score == 100)
{
speed = speed + 1.0f;
}
}
But char speed is staying 3.0 without any change
Where`s my mistake?
Maybe you score variable never get the 100 value, and the if never starts.
You can try adding a line like:
Debug.Log(score, gameobject);
in the function increaseSpeed() and execute the game, checking the console, it will say you the value of score. Or using breakpoints for debugging.
Ants0li
November 29, 2014, 2:00pm
3
zRedCode:
Maybe you score variable never get the 100 value, and the if never starts.
You can try adding a line like:
Debug.Log(score, gameobject);
in the function increaseSpeed() and execute the game, checking the console, it will say you the value of score. Or using breakpoints for debugging.
I dont know how does it works, i
m just added this line in my code, but nothing happens. Doesnt matter, i
ve checked my “Score-system” it works totally correctly.
Also, system which send score-info is working too. I don`t have any ideas.
Basic question: do you call that function in Update?
Ants0li
November 29, 2014, 2:08pm
5
Uhm… Maybe im so newbie at this, but i can
t understand: is it necessarily?
No, i don`t. How can i do it?
Ants0li
November 29, 2014, 2:12pm
6
Okay, i`ve added if statement in Update.
If i keep *10 (score) nothing happens, but if i will change it to 100 my char going to fly away.
Can you post the full script?
Ants0li
November 29, 2014, 2:17pm
8
I have few scripts in my game. Maybe i can upload full project for you? Or you need just these scripts ( score and movement ) ?
i need the class where is the code posted in the open post.
Never used an OOP language?
The Function IncreaseScore isn’t called on the attached script, so the code will never runned. There is a class that calls that function? If not, thats why the code not works, if yes, post that class.
Ants0li
November 29, 2014, 2:36pm
12
zRedCode:
Never used an OOP language?
The Function IncreaseScore isn’t called on the attached script, so the code will never runned. There is a class that calls that function? If not, thats why the code not works, if yes, post that class.
uhm… I think i have some big troubles in my knowledge.
What should i do?
Should i create public, void or something another?
no, you not have to create anything, simply call the function. A void is a type of function. Just look this video , it explains variables and functions.
Ants0li
November 29, 2014, 2:48pm
14
zRedCode:
no, you not have to create anything, simply call the function. A void is a type of function. Just look this video , it explains variables and functions.
I cant understand what i should change. I have some void ( which is function ), i have added something to Update void. I can
t understand anyway.
To call a function you should write in a called function FunctionName(parameters);
For example:
void Update()
{
//calling the FunctionA function
FunctionA();
}
if you still not understand i suggest to follow all the scripting tutorials in the learn section of unity3d.com
Ants0li
November 29, 2014, 3:06pm
16
zRedCode:
To call a function you should write in a called function FunctionName(parameters);
For example:
void Update()
{
//calling the FunctionA function
FunctionA();
}
if you still not understand i suggest to follow all the scripting tutorials in the learn section of unity3d.com
Oh yeah, my fail. Sure, i can understand you now.
I changed my code a bit, but it still doesnt work.
Now i have something like that:
public float baseSpeed = 3.0f;
public float speed = 0;
int score = 0;
void IncreaseSpeed()
{
speed = baseSpeed + (int)score/100;
}
void Start()
{
groundcheck = transform.Find ("groundcheck");
}
void Update()
{
IncreaseSpeed();
score = PlayerPrefs.GetInt ("Score") * 10;
if (Input.GetKeyDown(KeyCode.Space))
jump = true;
}
Maybe move this line score = PlayerPrefs.GetInt ("Score") * 10;
from the Start function to the Update function
Ants0li
November 29, 2014, 6:39pm
18
Yes, i moved it to Update
True, didn’t see that… What is the GUILabel of the score showing…
Ants0li
November 29, 2014, 7:08pm
20
First label is for GAME OVER title, second is for the total score, and the last button is for RETRY fuction.