Using strings for GetComponent slows down your game.
I would use the inheritance for that when you inhert from a Class that inherts from a MonoBehaviour and hat the [Serializable] Attribute before the class header you can add the Script to the Editor. In the Script where you want to use your Script I would make a public field with the Type of the Base Class so you that you can set all derived Classes in the Editor for this Field.
Then the code is cleaner.
public abstract class UniversalScript : MonoBehaviour{
public virtual SomeMethod( ){
}
}
[Serializable]
public class SpiderScript : UniversalScript{
}
public class SomeScript : MonoBehaviour{
public UniversalScript uniScript;
void Update(){
uniScript.SomeMethod();
}
}
thanks for the answers guys but it seems to complicated for me atm I’m a real beginner and to do as mentioned i need to change the whole game.
for future generation use what posters above said and if not create script that only contains public float health and attach it to anything that have a health and reference that float from the other “on hit” or what ever script name.