- Home /
counting in 3 different gui texts C#
i have made the code unther this text. what it should do is counting 12 times 3 arrows hitting a target. in the target are 5 rings. each ring has another tag. i have a script to count an overall score but now i need a script that counts points for three diffrent aarows and then makes the variables empty agin to count 3 arrows again. and that 12 times. but the script is not doing it. it just counts wrong. this link is a picture of what happens. the green count is my overall count and that is correct but the other tree counts ar wrong. http://prntscr.com/3oofbb
can anyone make my script work?
thanks
jorg
script:
using UnityEngine; using System.Collections; public class Count3pijlen: MonoBehaviour { public GUIText countText1; public GUIText countText2; public GUIText countText3; private static int count1; private static int count2; private static int count3; private int i; private int j; public void Start() { count1 = 0; count2 = 0; count3 = 0; SetCountText1(); SetCountText2(); SetCountText3(); } public void OnMouseUp() { for (j = 0; j < 12; j++) { for (i = 0; i < 3; i++) { if (i == 0) { switch (gameObject.tag) { case "White": count1 += 1; break; case "Black": count1 += 2; break; case "Blue": count1 += 3; break; case "Red": count1 += 4; break; case "Yellow": count1 += 5; break; } SetCountText1 (); } if (i == 1) { switch (gameObject.tag) { case "White": count2 += 1; break; case "Black": count2 += 2; break; case "Blue": count2 += 3; break; case "Red": count2 += 4; break; case "Yellow": count2 += 5; break; } SetCountText2 (); } if (i == 2) { switch (gameObject.tag) { case "White": count3 += 1; break; case "Black": count3 += 2; break; case "Blue": count3 += 3; break; case "Red": count3 += 4; break; case "Yellow": count3 += 5; break; } SetCountText3 (); } } } } void SetCountText1() { countText1.text = "Pijl 1: " + count1.ToString (); } void SetCountText2() { countText2.text = "Pijl 2: " + count3.ToString (); } void SetCountText3() { countText3.text = "Pijl 3: " + count3.ToString (); } }
Your answer
![](https://koobas.hobune.stream/wayback/20220613150528im_/https://answers.unity.com/themes/thub/images/avi.jpg)