If I have an empty variable and I haven’t put anything into it yet, is there anyway to determine what type the variable name itself is?
Ex:
var emptyVar : stateManagerScript; //create integer variable with no element inside
if(emptyVar.type == stateManagerScript)
Debug.Log("state manager");
else if(emptyVar.type == movementScript)
Debug.Log("movement script");
Is there any way to do something like this? When I try it with a script named “stateManagerScript” and “movementScript” in my assets folder I get an object reference error.
You’ve made the type of “emptyVar” be “stateManagerScript”, so it can never be “movementScript” or any other type, regardless of whether anything has been assigned to it or not.
–Eric
Yes but I’d like to check which it is capable of holding.
Ultimately I’d like to make a system which takes in a variable and finds the correct script reference on the gameObject for it. This way I could do Setup(emptyVar) and it would determine the script type, locate the script, then set emptyVar to the found script reference.
Thus I’d like to be able to input the variable and, by extension, its type as well without having to specify again.
It’s only capable of holding stateManagerScript, so there’s no need to check. It sounds like you should probably be using SendMessage instead of going about things this way.
–Eric