getDay

As an exercise I have made 7 buttons in Unity. Each day of the week corresponds with a button (button 0 = sunday, button 1 = monday, …).
The intention is that you have to click on the button which corresponds with the actual day.

For example, today it’s sunday. When you click on button 0, you will hear an audioclip “Good”.
But if you click on button 1, you will hear “Not good”.
If you do this tomorrow, you will hear “Not good” if you hit button 0 and hear “Good” if you hit button 1.
So you will need the actual day from the computer.

I’m a beginner with javascript and I’m trying to realise this with the next script:

    var soundGood : AudioClip;
    var soundNotGood : AudioClip;
    var d = new Date();
    var curr_day = d.getDay();

    function OnMouseUp() 
    {
	    if (curr_day == 0)
	    {
	    	audio.PlayOneShot(soundGood);
	    }
     
            else if (curr_day == 1 || curr_day == 2 || curr_day == 3 || curr_day == 4 || curr_day == 5 || curr_day == 6)
            {
		audio.PlayOneShot(soundNotGood);
            }
   }

This doesn’t work.
I have the next error: MissingMethodException: Method not found: ‘System.DateTime.getDay’.
I think I overlook something but I have no idea what. What do I have to do to make it work?

To me, what you are doing seems fancy. What I would do would be more like this…

var dayActual : int; // global day of week.
var dayBtn : int; // day of button

Then in your btn input…
if (dayBtn == dayActual)
Yeh();
if(dayBtn != dayActual)
Boo();

Thanks for reply.

But how do I get the actual day from the computersystem?

DateTime Struct (System) | Microsoft Learn, also DateTime Struct (System) | Microsoft Learn. Everything there applies to Unityscript as well as C#.

–Eric

Well, you could just have a dayManager.
A script that you set the day in.

Edit. My theories still apply but i now see you need the actual day.

This thread solved my problem:
http://forum.unity3d.com/threads/89237-System-date-time-question

I use the DayOfWeek property:
if (System.DateTime.Now.DayOfWeek == System.DayOfWeek.Saturday)

Thank you for reply.