Attempting to create a Utility class of static functions. Which object references do I need for Unity's built in functions, and where do I put them?

Trying to create a class of static functions, that I can call in a similar fashion to ‘Vector3.RotateAround’, ‘Vector3.Normalize’, etc. Here’s what I have so far:

using UnityEngine;

    public class UtilitySetMono : MonoBehaviour
    {
        public static void MoveOnKeyboardPress(KeyCode key, Vector3 direction)
        {
            if (Input.GetKey(key))
            {         
                transform.Translate(direction * Time.deltaTime);
            }
        }
    }

The first part of the ‘transform.Translate’ function, the word ‘transform’, is throwing the following error:

An object reference is required for the non-static field method or property ‘Component.transform’.

Where should I insert the object reference, and what do I need to type there?

This could be an extension method for the Transform class:

public static void MoveOnKeyboardPress(this Transform transform, KeyCode key, Vector3 direction)

And then you just call it on any transform:

transform.MoveOnKeyboardPress(key, direction);

You can not access non-static (transform here) inside a static functions. You should use singleton pattern. also you can fix just this function by passing transform to it

 using UnityEngine;
 
     public class UtilitySetMono : MonoBehaviour
     {
         public static void MoveOnKeyboardPress(Transform trans, KeyCode key, Vector3 direction)
         {
             if (Input.GetKey(key))
             {         
                 trans.Translate(direction * Time.deltaTime);
             }
         }
     }

I think most of these points have been made in previous answers and comments, just wanted to put them together & summarize. Everyone should feel free to edit this.

public static class ExtensionClassName
{
 
   static public Vector2 RotateAboutPoint(this Vector2 pointToRotate, Vector2 centerPoint, float angle)
     {..blah..}

   static public Vector2 RotateAboutPoint2(Vector2 pointToRotate, Vector2 centerPoint, float angle)
     {..blah..}

   static float favoriteAngle=30.0f;
}

Notice the two ways the RotateAboutPoint functions’ parameters are defined: the first one has the keyword “this” in front of it.
This is no more than a neat syntax trick, which allow this function to be CALLED like so:

pointToRotate.RotateAboutPoint(centerPoint, angle);  //Where pointToRotate is a Vector2 variable.

This is functionally exactly the same as NOT using the “this” keyword, and calling the function like so:

ExtensionClassName.RotateAboutPoint2(pointToRoate, centerPoint,angle);

Either way, because these are static functions, you must pass in (or otherwise make accessible) ALL the information needed to compute the return value.

Other ways to make values accessible to static functions, is to store them in static variables. For example the static float favoriteAngle can be read and written by both RotateAboutPoint functions. It can ALSO be access ANYWHERE this class is available with:

ExtensionClassName.favoriteAngle

Limitations: the name of the static class holding these functios must be used, unless the “This” keyword is specified. Alas, the class names Vector2 and Vector3 and similar, are already defined, so we MUST use a unique class name here. this means we CANNOT define, for example, a function called like so: Vector2.RotateAboutPoint(pointToRoate, centerPoint,angle);

Hi.

Static function can only access static variables.

Why do you need this function to be static ?