I want to access a non-specific script. That script’s name depends on the object’s tag;
for example if the tag of the object that holds the script is “Door1”, script’s name will be “interactScriptDoor1” and if the tag is “LockedDoor”, the script’s name would be “interactScriptLockedDoor”. Note that these scripts are already made and named.
I’m attempting to call these scripts from another script on another object, which works fine. The problem is that I have to make them all separately: I always have to declare the type by the name of the script:
For example:
private interactScriptDoor1 launchItem1;
private interactScriptLockedDoor launchItem2;
...
and then:
launchItem1=targetedObject.GetComponent<interactScriptDoor1>();
launchItem2=targetedObject.GetComponent<interactScriptLockedDoor>();
The point is that every object has only one interact script; What I wish to achieve is something like
private Script launchItem; //script not being any existing script(only type)
and declare it with:
launchItem=targetedObject.GetComponent("InteractScript"+targetedObject.tag);
The problem is that I can’t declare launchItem without declaring it with specific script in the first place.
If anyone wonders why would I want this, it’s for avoiding constantly updating interaction script when new types of object appears.
Please help.