My program creates a number of objects from a subset of many possible object types (object1, object2, object3) with Instantiate().
GameObject newObject = Instantiate(object, position, Quaternion.identity) as GameObject;
It then creates a script in that new object, depending on which type of object it is.
newObject.AddComponent();
Now, I want to be able to pass a reference to this new script (Object1Behaviour) to newObject so that it can use methods from Object1Behaviour at a later time. However, when I try to pass Object1Behaviour directly through a function call, I get the error:
CS0119: Expression denotes a type', where a variable’, value' or method group’ was expected
why not just in prefab set script for object instead of adding
also your question is very unclear, you want to have refference to Object1Behaviour in Object1Behaviour? or Object1Behaviour to a gameobject newObject?
In general, if you want to store script for refference for later use
I’ll try to give you some more details so my question is more clear.
I have set up my program so that there is a BasicObject prefab with a BasicObjectBehaviour script. In the scene, a Controller object creates many copies of this BasicObject, but determines their “subtype” and attaches a script for behaviour specific to that object subtype (in this case, Object1Behaviour for the subtype Object1). This new attached script has functions that I want to be able to call, but I can’t figure out how to call these functions from the BasicObjectBehaviour script.
I could do something like this:
Object1Behaviour object1script = newObject.AddComponent();
But I don’t know how I would pass this reference to the BasicObjectBehaviour script from the Controller object. Do you know how I could do this?
I tried to do that, but I ran into an issue. When I am declaring somePublicVariable in OtherScript, what do I put as the type? I would have to put Object1Behaviour as the type in this case, but the type might also have to be Object2Behaviour or Object3Behaviour, since the BasicObject’s OtherScript is common to all of the object subtypes.