Bear with me, I’ve been learning Unity for all of 3 hours and half of that was trying to research this question. I have a fresh project, 2d, with only the main camera. I right-clicked my Asset folder, Create > C# script (Main.cs) and added some code to draw a rectangle at a certain position in the OnGui method.
However, I’ve gathered that this won’t work until the script is attached to any game object in the hierarchy. Seems idiosyncratic, but whatever. Is it possible to programmatically attach my script (Main) to the main camera?
I tried this in Start but to no avail:
Camera.main.gameObject.AddComponent();
I’d imagine there are a gazillion ways of doing this through the inspector panels or other drag-drop goodies but, hey I’m idiosyncratic myself and like doing everything programmatically - if possible. Coding purist, if you will.
So, is this possible?