I create some game object on runtime… for example I have 3 GameObject: cube, plane, car. I want add onMouseDown Event cube and plane, not car… How I can it?
There are two approaches. The first is that you create a prefab that already has the script on it and use Instantiate() to create the object at runtime. More information on prefabs here:
The second is you write the script and then you attache it at runtime. Say the script is called ‘MouseHandler’ and you want to attach it at runtime: