1. Is it possible to add a new component to a GameObject using scripting?
I have a mesh where I have removed the Mesh Renderer-component and now I want to add it again using javascripting…but the manual only mentions GetComponent…
2. What’s the best way to have variables that are globally accessible in Unity?
I want to have some variables that all my scripts can “see”, no matter which gameobjects they are are attached to.
As for (1), I think you are looking for AddComponent:
As for (2): Good question! Until now I just queried the object that I needed, and then accessed its variables, but indeed global vars would be nice, a kind of a “world” object.