- Home /
This question was
closed May 31, 2014 at 01:25 AM by
Jun Hin for the following reason:
The question is answered, right answer was accepted
Formatting Calendar, Iterating through list of strings.
I'm trying to format a calendar so that it displays the day and below it the date. What I've done now gives me this result:
As you can see I'm having trouble getting the days to display properly and I'm out of ideas on how to fix it.
My code:
public int firstJan;
public int daysfromnow;
public string firstDayOfYear;
private string dayName;
List<string> dayList = new List<string>(7);
void Update ()
{
firstJan = DateTime.Now.DayOfYear;
DateTime Today = DateTime.Now;
DateTime answer = Today.AddDays(-firstJan + daysfromnow);
firstDayOfYear = answer.DayOfWeek.ToString().Substring(0, 3);
dayName = firstDayOfYear;
dayList.Add(dayName);
for (int i = 0; i < daysfromnow; i++)
{
Transform child = transform.GetChild(i);
child.GetComponent<UILabel>().text = dayList[i] + "\n" + transform.GetChild(i).name;
daysfromnow += 1;
if (daysfromnow >= transform.childCount)
daysfromnow = transform.childCount;
}
}
calendar.png
(55.2 kB)
Comment
Best Answer
Answer by wijesijp · May 30, 2014 at 11:49 AM
I am puzzled why you do this in Update method
Thanks for the hint, I managed to fix it by putting all of the day calculation stuff into it's own function then calling it in the for loop I have in Update.