Question by
AlexTemina · Nov 23, 2015 at 12:54 PM ·
spritescreatecomponents
do something every time a Sprite is added to the Scene
I want to add a Script every time a new Sprite is added to the Scene or created, because in our games Sprites should always have a script that controls textures and something else. How can I do this?
Comment
Best Answer
Answer by Deadcow_ · Nov 23, 2015 at 02:43 PM
As I answered you here http://answers.unity3d.com/comments/1102243/view.html you may create simple class with InitializeOnLoad attribute, in static constructor you should sucscribe to hierarchy update event:
EditorApplication.hierarchyWindowChanged += HierarchyUpdate;
and in HierarchyUpdate function - find and check all Sprites on the scene or something like this. Probably won't be too complicated, but may occure some performance hit on large scenes