hi!
I want to create a timer function in c# to do some timing stuff
To do that I would like to create a method like this:
void SetTimer(float TimeToWait, Object(??) CallbackFunction)
and then use it like so:
SetTimer(3.0f, TheMethodThatNeedsToBeCalledWhenTheTimerIsFinished);
void TheMethodThatNeedsToBeCalledWhenTheTimerIsFinished()
{
// do some stuff
}
Is this possible and if so, how do I do it? I read some stuff about delegates but I have to admit that I don’t really understood that…
Look into coroutines, they’ll be a big help here. For example, start here with StartCoroutine. 
I have it working now, here’s what I did:
I created a TimerFunctionsClass:
using UnityEngine;
public class TimerFunctionsClass: MonoBehaviour
{
public delegate void OnTimerEvent();
private OnTimerEvent CallBackFunction; // the function that is called when the time is up
private float OriginalTimeInterval; // used for resetting
private float TimeLeft; // used for counting down
private bool Active = false;
// setup the timer: how long should the timer wait and which function should it call when the event is triggered
public void SetTimer(float TimeInterval, OnTimerEvent NewCallBackFunction)
{
TimeLeft = TimeInterval;
CallBackFunction = NewCallBackFunction;
}
// actually start the timer:
public void StartTimer()
{
Active = true;
}
// I'm not using this, but whatever:
public void StopTimer()
{
Active = false;
}
// ohwell
public void ResetTimer()
{
TimeLeft = OriginalTimeInterval;
}
public void DestroyTimer()
{
Destroy(this);
}
// TimeLeft is decreased by Time.deltaTime every tick, if it hits 0 then the CallBackFunction is called
void Update()
{
if (Active == true)
{
TimeLeft -= Time.deltaTime;
if (TimeLeft <= 0)
{
CallBackFunction();
StopTimer();
DestroyTimer();
}
}
}
}
And here is how I use the timer in my game code:
void DoSomething()
{
Debug.Log("do something!");
}
void Start()
{
TimerFunctionsClass MyTimer;
gameObject.AddComponent("TimerFunctionsClass");
MyTimer = (TimerFunctionsClass)gameObject.GetComponent(typeof(TimerFunctionsClass));
MyTimer.SetTimer(10.0f, DoSomething);
MyTimer.StartTimer();
}
it’s probably not-so-good-code but it works for me 
Thats actually bad code, not “not so good” I fear
A simple coroutine and yield return WaitForSeconds(yourWaitTime); would do the same thing
pause is not needed as setting the timescale to 0 will pause coroutines too and ending them is possible through StopCoroutine
I tried using
yield return WaitForSeconds(yourWaitTime);
but I could not get it to work, nomatter what I tried the error messages just kept becoming more and more exotic.
Can you give me example code of a “good version” of this class? The code above works as intended but I suppose using WaitForSeconds would be more efficient.
By the way, the delegate stuff is correct right?
check out the script docs on StartCoroutine and WaitForSeconds
they will give you an idea on coroutines.