Unity: Do object declaration inside coroutine have more performance cost than declaring it globally?

by Mark S   Last Updated March 16, 2019 10:13 AM - source

For example this:

public void attack()
{
    StartCoroutine(attackCo());
}
IEnumerator attackCo()
{
    GameObject tempGo;
    for(int i = 0; i < times; i++)
    {
        tempGo = Instantiate(go);
        tempGo.transform = Vector3.zero;
        tempGo.transform.LookAt = target;
        yield return new WaitForSeconds(.5f); 
    }
}

Compared to this:

class EnemyBehaviour
    {
        GameObject tempGo;
        public void attack()
        {
            StartCoroutine(attackCo());
        }
        IEnumerator attackCo()
        {
            for(int i = 0; i < times; i++)
            {
                tempGo = Instantiate(go);
                tempGo.transform = Vector3.zero;
                tempGo.transform.LookAt = target;
                yield return new WaitForSeconds(.5f);
            }
        }
    }


Related Questions


MeshMemory causing constant spikes

Updated February 25, 2018 19:13 PM



Sprites power of 2 are better?

Updated June 18, 2015 00:05 AM