Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How can i set an alarm sound when it goes to a specific hour just like lunch

Discussion in 'Scripting' started by Meliodass, Mar 4, 2015.

  1. Meliodass

    Meliodass

    Joined:
    Feb 8, 2015
    Posts:
    32
    Hey guys i don't know how to start this and my questions speaks itself i just want to know or maybe you guys could suggest cause i`m a beginner :(
     
  2. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
    I don't understand your question...What?
     
  3. chrisall76

    chrisall76

    Joined:
    May 19, 2012
    Posts:
    667
  4. knr_

    knr_

    Joined:
    Nov 17, 2012
    Posts:
    258
    Hi Meliodass,

    For this I think the easiest thing to do is to use System.DateTime.Now

    Example:

    Code (CSharp):
    1. using System;
    2.  
    3. public class SomeClass
    4. {
    5.    public void SomeFunction()
    6.    {
    7.       Int32 currentHour = DateTime.Now.Hour;
    8.  
    9.       if (currentHour == 12) // I am guessing this is noon
    10.       {
    11.          // Lunch time!
    12.       }
    13.    }
    14. }
    Of course, you can put this code inside a MonoBehaviour class too. Example:

    Code (CSharp):
    1. using System;
    2. using UnityEngine;
    3.  
    4. public class SomeClass : MonoBehaviour
    5. {
    6.    public void Update()
    7.    {
    8.       Int32 currentHour = DateTime.Now.Hour;
    9.  
    10.       if (currentHour == 12) // I am guessing this is noon
    11.       {
    12.          // Lunch time!
    13.       }
    14.    }
    15. }