launch a function a little after the start function

Good morning, everyone,

I am a beginner in video game creation.

When launching my game in a start function all my varables recover the data stored in variables of a different gameObject that is initialized during an Awake function.

But not everything has time to charge.

My question is simple, is there any way to launch a function a little after the start function ?

Which could look like this :

void Start ()
    {

        Wait(2 secondes);
        Go();
    }

void Go()
    {
        Debug.Log("Yes");
        
    }

You could use Invoke, or a coroutine.

Invoke:

void Start() {
Invoke("Go", 2f);
}

public void Go() {
Debug.Log("Yes");
}

Coroutine:

IEnumerator Start() {
yield return WaitForSeconds(2f);
Go();
}

Coroutine is probably the better choice, though I do recommend doing some further reading on coroutines before deploying them everywhere.

Note also that before Start() is invoked, the Awake() function is invoked.

Just want to mention, when using Invoke(), instead of passing the method name as a string, you can use the C# nameof operator to pass in the method name instead. This way, if you change the method name, it will reflect here as well:

void Start() {
   Invoke(nameof(Foo), 2f);
}

void Foo() {

}

If you don’t want to mess with a coroutine or invoke just yet, you can do it the messy way in Update

float startTime;
bool doneMyThing = false;

void Start ()
{
    startTime = Time.time;
}

void Update()
{
    if ((doneMyThing == false) && (Time.time >= startTime + 2f))
    {
        Go();
        doneMyThing = true;
    }
}

It is certainly not as clean looking, but beginners sometimes find things like coroutines intimidating.