The main problem is that the GetComponent() parameter doesn’t work if I use a variable of type String in it, but I need to use a variable for the GetComponent() parameter because in my game the character picks up different weapons and I need to use a variable that’s always equel to the weapons’s script’s name.
Here’s a part of my script: (JS)
//The variables I used:
//
var weapon : Transform;
//The script name on any of my weapons will always be the weapon's name with "Script" added at the end.
var weaponScriptName : String = weapon.gameObject.name + "Script";
//The script I need to use, but it doens't work:
weapon.GetComponent(weaponScriptName).attack = true;
//The script that works but only if I hardcode the weapon's name in every case.
weapon.GetComponent(SwordScript).attack = true; //weapon in this case is "Sword".