Get other GameObject's script name

Hello everyone,

I’m trying to create a system in which you can swap different guns, each one with a different script, so I need a way to access the methods in each script depending on the weapon the character is using from the character’s script, but I can’t find a suitable way to do it.

Thanks

Basic oop rules inheritance and polymoprhism. Create a gun class and create Fire(), Reload() vs. methods inside it. Than derive your each gun from that base class and override all of your methods in each gun script depending on your gun type. So you could call just one method but each gun will react different.

you can have a parent class for all the classes something like this

PARENT

public class Weapon : MonoBehaviour {

}

Childs

public class Weapon1 : Weapon {
}

public class Weapon2 : Weapon {
}

and access the type of your weapon

Debug.Log(yourWeapon.GetComponent<Weapon>().GetType().Name);//this will give your the name of the clas