One script with common funtions/methods

Hello everyone!
Before I used GameMaker and there I could create a script with some common functions and after using it with different objects (for example write function of damage and use it for player and for enemy). Now I want to do something like this in Unity, but I really don’t understand how, because

  1. Maybe I am wrong, but I suppose that I can use scrit if it is attached to an object
    then I decided to attach to GameManager object, but
  2. if I want to use the method in my Player script, I have to create a variable, find object GameManager, get component(script) of the object and only after that I can use this method
    But it looks very complicated for this purpose. Maybe there are some simpler way to do this? I tried to find the answer by myself but I failed

If you want a class that just contains helper functions, make it a static class.

public static class MyHelperClass
{
	public static void MyHelperMethod() { ... }
}

// usage
MyHelperClass.MyHelperMethod();

Ideally you name the class something relevant to the methods you’re going to put into it.

Thak you very much! And attach it to Game Manager object (for example)?

It’s a static class, ergo it can’t be instanced. You don’t need to attach it to anything.

Only your custom classes derived from MonoBehaviour need to be attached to game objects.

Thank you very much for your help