Yeah, actually now that I read your question again I see that you want X to change. This is not possible. But if you tell us what you want to do we might be able to offer some suggestions.
i guess the heart of my question was just how to pull data from many different scripts.
I am making an attack method, i want to pass it 2 game objects(attacker, and target). it will then check some stuff; weapon, armor and attributes.
but the problem is that the scripts i have made have different names for the player(PlayerScript) and the enemy(EnemyScript), and Other(OtherScript).
So the Attack() method is passed the 2 objects with different scripts and need to get data from each. i was hoping to make this method to soft the script by tag oth some other method and end up with a single variable.
as i am writing this it seems maybe the best idea is to just rename those scripts.
I’d create a new component script called, let’s say, Combat. Define your weapons, armour, resistences, attributes and what not in there. Add that new component to both your Player and Enemy and use that in your Attack function calculations.
That way, if you add a new type of combatant in the future, you don’t have to go back into this code and change anything.
Yes. But note you can inherit only one actual class (MonoBehaviour in this case), but many interfaces.
More like it will force you to add all the methods in IAttack to your class. You can’t put any actual code in the methods of an interface; it’s basically just saying “These are the methods that have to be in any class that inherits me”. The actual code for Attack() goes into each class that inherits it and they can all have different code, so the version of Attack() in PlayerScript could do player-specific stuff like update your stamina bar on the screen while the version of Attack() in EnemyScript could play an animation and make the enemy flash red or whatever.
Though I guess I should add… if the code for the two different versions is almost all identical, then it would probably be better to have a single component that they both can share, like Grozzler suggested, so that you don’t just have two different copies of the same code in two different places.