I am making a process to increase the score by +1 when hitting a bullet.
For that purpose, I wrote a code to display the score (upper side) and a code to increase the score by +1 when the bullet hits (lower side).
public class ScoreCounter: MonoBehaviourPunCallbacks
{
Text Score Text;
int score;
public int Score
{
set
{
ScoreUpdate ();
score = value;
}
get
{
return score;
}
}
void Start ()
{
ScoreText = GetComponent<Text>();
Score = 0;
}
void ScoreUpdate ()
{
ScoreText.text = "Score:" + Score.ToString ("00");
Debug.Log (Score);
}
}
void OnTriggerEnter (Collider other)
{
if (other.gameObject.tag == ("Player"))
{
scoreCounter.Score + = 1;
Debug.Log (scoreCounter.Score);
}
}
The code for displaying the score is attached to the UI that actually displays the score.
The code that adds +1 to the score when the bullet hits is attached to the bullet.
But these two codes didn't work.
Specifically, the value of the Score variable that has been incremented by +1 on the bullet side and the value of the Score variable on the ScoreCounter side that actually displays the score are out of alignment.
For example, if the value of the Score variable on the bullet side is 1, the value on the Score Counter side is 0, if the value of the Score variable on the bullet side is 2, the value on the Score Counter side is 1, and so on. I will end up.
I don't know what caused this to happen.
Is there a problem with the two codes in this question?
Or is it likely that something else is wrong?
If i have problems with these two codes, please tell me which part is the problem.
-
Answer # 1
-
Answer # 2
set
{
ScoreUpdate ();
score = value;
}These two lines are upside down, aren't they?
Related articles
- c # - i want to programmatically put the character variable set in another script into text (script)
- c # - can't get variable of script attached to ui in another ui
- c # - get variable values from aspnet code-behind
- ruby - is there a way to use the value (variable data) in another class that has no inheritance relationship?
- c++ - i want to declare a variable in one class in another class
- c # - error by assets received from another person in unity
- c # - [unity] i want to pass a variable from onenddrag to ondrop
- c # - about changing the column order of datasettable in visual studio
- pointer reference to variable in class layer in c #
- about changing the interval property of the c # timer class
- the array variable created by c # for statement is said to not exist
- [c #] in unity, i want to repeatedly move the cube object to the z axis, but a variable conversion error occurs
- c # - i want to inherit enum with another script
- c # - about public
- vuejs - i want to put the variable received from the parent into a variable of another name
- unity2d - i want to update the variable of another scene from another scene
- c # - when referencing public class properties
- c # - i want to reference a variable in the script of the parent object
- c # - why do i get an error for a method when the class variable definition can be private?
- c # - [unity] i don't know how to use "pointerpress" of pointereventdata
- c # - i want to slowly rotate the model to a fixed angle when the flag is set, and slowly return it to the original angle when t
- c # - i want to rank in a racing game considering the number of laps unity
- c # - [unity] i can't update and get custom properties in photon
- c # - if you hit a bullet at a close distance, the speed will be 0
- c # - can i use 3 cameras?
- c # - i want to switch multiple sound sources in a scene with unity and make a scene transition
- c # - [unity] in tps 3d games on smartphones, if you are touching the joystick on the ui, you want to disable the input to the c
- c # - [unity] if you stop at a breakpoint and then start playing again, the network object created by photon will disappear
- c # - i want to duplicate multiple and change the hp bar for each
I think it's because of the processing order of this part.
ScoreCounter
ofScore property
If set to, the value will bevalue
It is handed over atScoreUpdate
Since being calledscore
A new value has been assigned to.