Question by
artem_levitin · Nov 08, 2021 at 05:04 PM ·
score
How to make a score counter?
I implemented Capture mode in my project. There are two teams in the game: blue and red. I want that if a team controls a point, then for 1 second of holding, the team (which holds it) is awarded 2 points. And in order to win, one or another team must score 500 points. How to do it?
{ private Coroutine CoroutineZaxvat;
public int teamBlue;
public int teamRed;
public string statusPoint;
public Image ImagePoint;
private void OnTriggerEnter(Collider other)
{
if (CoroutineZaxvat == null) CoroutineZaxvat = StartCoroutine(Zaxvat());
if(other.gameObject.GetComponent<FPSControllerLPFP.FpsControllerLPFP>().team == "Blue") teamBlue++;
else if(other.gameObject.GetComponent<FPSControllerLPFP.FpsControllerLPFP>().team == "Red") teamRed++;
}
private void OnTriggerExit(Collider other)
{
if(other.gameObject.GetComponent<FPSControllerLPFP.FpsControllerLPFP>().team == "Blue") teamBlue--;
else if(other.gameObject.GetComponent<FPSControllerLPFP.FpsControllerLPFP>().team == "Red") teamRed--;
}
IEnumerator Zaxvat()
{
while(true)
{
if(teamBlue > teamRed)
{
if(statusPoint == "" || statusPoint == "ZaxvatBlue")
{
if(statusPoint != "ZaxvatBlue") statusPoint = "ZaxvatBlue";
if(ImagePoint.color != new Color(0,0,1,1)) ImagePoint.color = new Color(0,0,1,1);
ImagePoint.fillAmount += 0.002f;
if(ImagePoint.fillAmount == 1) statusPoint = "FullZaxvatBlue";
}
else if(statusPoint == "ZaxvatRed" || statusPoint == "FullZaxvatRed")
{
ImagePoint.fillAmount -= 0.003f;
if(ImagePoint.fillAmount == 0) statusPoint = "";
}
}
else if(teamBlue < teamRed)
{
if(statusPoint == "" || statusPoint == "ZaxvatRed")
{
if(statusPoint != "ZaxvatRed") statusPoint = "ZaxvatRed";
if(ImagePoint.color != new Color(1,0,0,1)) ImagePoint.color = new Color(1,0,0,1);
ImagePoint.fillAmount += 0.002f;
if(ImagePoint.fillAmount == 1) statusPoint = "FullZaxvatRed";
}
else if(statusPoint == "ZaxvatBlue" || statusPoint == "FullZaxvatBlue")
{
ImagePoint.fillAmount -= 0.003f;
if(ImagePoint.fillAmount == 0) statusPoint = "";
}
}
else if(teamBlue == 0 && teamRed == 0)
{
if(statusPoint != "FullZaxvatRed" && statusPoint != "FullZaxvatBlue")
{
if(ImagePoint.fillAmount != 0f)
{
ImagePoint.fillAmount -= 0.002f;
if(ImagePoint.fillAmount == 0f)
{
StopCoroutine(CoroutineZaxvat);
CoroutineZaxvat = null;
statusPoint = "";
}
}
}
else if(statusPoint == "FullZaxvatRed" || statusPoint == "FullZaxvatBlue")
{
if(ImagePoint.fillAmount != 1f)
{
ImagePoint.fillAmount -= 0.002f;
if(ImagePoint.fillAmount == 1f)
{
StopCoroutine(CoroutineZaxvat);
CoroutineZaxvat = null;
}
}
}
}
yield return new WaitForFixedUpdate();
}
}
}
Here is my script. I really ask you to help me.
Comment
Your answer
Follow this Question
Related Questions
when i reload the scene the score number remains the same and doesnt revert back to zero 1 Answer
Help to Stop Level Load Loop 2 Answers
Hello everyone I have a problem with rounding number of my score 2 Answers
change scene by score 0 Answers
i developed a game space shooter i set a condition when player reached 1 Answer