i'm making a game to put on kongregate, in order to use their API, I have to send a function for it to call when the API is initialized. For some reason, the script this function is in has to be attached to a gameobject (so that the function's object is a gameobject).
(it really annoys me that for a lot of things, unity developers are being forced to use gameobjects for no good reason)
to do this I did this:
//Kong = new KongApi(); //nope, t moet weer aan een gameobject hangen
var object : GameObject;
object = new GameObject("MyUnityObject");
object.AddComponent(KongApi);
Object.DontDestroyOnLoad (object);
Kong = object.GetComponent(KongApi);
Kong.Start();
now this gives me an error for some reason, it claims DontDestroyOnLoad() doesn't exist. (I wrote Object. because this code isn't run in a script attached to a gameobject) when I remove that line, it compiles, but then I get a NullReferenceException: Object reference not set to an instance of an object for the Kong object, which means the GetComponent(KongApi) failed.
Anyone know what I'm doing wrong ?
EDIT:
it seems that scripts don't extend on Monobehaviour when you define the class in it ("class KongApi"), so because of this, it couldn't add it as a component. (that should be better documented IMO, though it actually does make sense). So that was fixed when I wrote it myself ("class KongApi extends MonoBehaviour").
but then there is still the problem that it doesn't seem to know DontDestroyOnLoad()
why is that ?