Here, is the highlisted code from the screenshot,
var enemy = Instantiate(wave.getEnemyPrefab(), wave.getEnemyWavePath()[0].transform.position, quaternion.identity);
enemy.GetComponent<enemyPath>().setWave(wave);
My doubt is, When will the script of an object will start to run after instantiating it?
Here, I’m instantiating Enemy object with the Instantiate(wave.getEnemyPrefab(), wave.getEnemyWavePath()[0].transform.position, quaternion.identity);
As per my assumption, the script of the Enemy object will start to run immediately after instantiation, Right? But in my case the script only runs after calling setWave(wave) method which is in enemy Object script (setWave(wave) method will set this.wave = wave in enemy script) .
I tried adding more lines after the Instantiate(wave.getEnemyPrefab(), wave.getEnemyWavePath()[0].transform.position, quaternion.identity); line but it seems like the enemy script only runs after ***Yield return new WaitForSeconds() ;
You can find the full code in the above screenshot I’ve included.
My Assumptions After testing: The enemy script runs only when the scope in which it is present ends or to say simply enemy script runs only at the end of the scope in which is is present.
Is my assumption right?