Question by
artem_levitin · Nov 08, 2021 at 05:04 PM ·
scoregames
How to make a score counter?
I'm making an army game. In this game there are two teams (blue and red) and capture points, like in battlefield or call of duty. I want to add a score counter so that when 1000 capture points are reached, one or another team wins.
{
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 the script, I hope someone will help me.
Comment
Your answer
Follow this Question
Related Questions
Game Ideas 1 Answer
Drag and drop like clash of clans 0 Answers
Making a high score script 0 Answers
Android apk fail 1 Answer
how to show score using panel 0 Answers