I could use some help on this one. Is it possible to dynamically type cast something? Here is what I am doing:
GameObject holder;
holder = (string.IsNullOrEmpty(action.tagOfHolder) == false) ? GameObject.FindGameObjectWithTag (action.tagOfHolder) : GameObject.Find(action.nameOfHolder);
if (holder.GetComponent (action.playerComponentScript) != null) {
Type mytype = Type.GetType (holder.GetComponent (action.playerComponentScript));
mytype script = holder.GetComponent (action.playerComponentScript);
I keep getting this error:
The type or namespace name `mytype’ could not be found. Are you missing a using directive or an assembly reference?
I don’t know the types of the component since this is decided based on what I am trying to find.
I want to dynamically type cast this so I can enable/disable the component. I can’t just do:
holder.GetComponent (action.playerComponentScript).enabled = true;
because it needs to know what type it is(Example):
holder.GetComponent ("Animation" as Animation).enabled = true;
Anyone have any direction for me?
NOTE: Other variations I have tried…
(holder.GetComponent (action.playerComponentScript) as myType).enabled = true;
(mytype)holder.GetComponent (action.playerComponentScript).enabled = true;