Quantcast
Channel: Questions in topic: "loops"
Viewing all articles
Browse latest Browse all 184

How to display a certain string out of array depending on a number?

$
0
0
Hello, I am trying to create a week system Monday through Sunday and I have these names in an array of string and I want them to be displayed accordingly to the number of that day. However, whenever I try to create a loop for it, something goes wrong. public TextMeshProUGUI dayText; public string[] dayName; public int countDays; public int dayNo; bool test; // Start is called before the first frame update void Start() { dayName[0] = "Monday"; dayName[1] = "Tuesday"; dayName[2] = "Wednesday"; dayName[3] = "Thursday"; dayName[4] = "Friday"; dayName[5] = "Saturday"; dayName[6] = "Sunday"; dayNo = 1; } // Update is called once per frame void Update() { CountDays(); } public void CountDays() { //TO DO //DISPLAY NAME OF THE DAY ACCORDING TO THE NUMBER if (Input.GetKeyDown(KeyCode.A)) { test = true; } if (test) { for (int i = 0; i < 7; i++) { dayText.text = dayName[i]; print(i); } } } As you can see in CountDays() function I was trying to put a condition to break out of the loop but immediately when I press "A" it changes from Monday to Sunday and I want it to be Monday -> Tuesday -> Wednesday etc. Please and thank you in advance for any help

Viewing all articles
Browse latest Browse all 184

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>