Understanding how scripts are used by gameobjects
Is there any way to create multiple instances of script dynamically? I have script that responds to clicks and moves the sprite to a new location. I gave this script to numerous objects, and not surprisingly, all of the sprite with access to that script moved to the location. I only want one object to move at a time, and wanted to see if there is a more efficient way than providing each their own individual script.
So is there a way to create multiple instances of this script dynamically or should I just write a longer script that will work?
Answer by TreyH · Feb 13, 2016 at 04:04 AM
@elothought Couple different ways to go about this. A tidy way to go about this is to have a manager for the click movements. I've sketched one out here:
Manager: http://pastebin.com/KJaQQdE1
Objects: http://pastebin.com/76SQTf67
ms paint: http://i.imgur.com/bArposb.png
When testing this, I attached the Manager script to the main camera for convenience and made 8 or so boxes arranged randomly across the scene.
Thanks @TreyH. I was planning on going the manager route if the dynamic script creation didn't exist. Elegant answer, and I appreciate the effort.