- Home /
Enable sprite through a single script and getcomponent called in ontriggerenter or through ~200 scripts and ontriggerenter, getcomponent called in start
Hi community, i just have started with unity and have the following setup:
--Parent (rigidbody2d) [this one get moved by rigidbody2d.MovePosition in fixedUpdate]
----200 Childs (Box collider 2d)
--childEnabler (rigidbody2d, boxcollider2d)
Now i added a script to all childs where i initialize the spriteRenderer at the start methode and enable them in the OnTriggerEnter2d methode.
My first question would be is it better performancewise to add a single script to childenabler and initialize the spriterenderer for each child in the OnTriggerEnter2d methode (multiple childs can enter per ms) ?
My second question would be can anyone explain me why my childs are lagging even if no script or anything else beside the box collider is attached to them on my phone ?
And may anyone can share an article/video with best practice for coding performancewise as its not easy as a beginner to understand that from the docs and trial and error.
Thanks.