An object reference is required for the non-static field, method, or property.

When trying to instantiate a projectile prefab, I called a method from another script and it gave me this error, but neither the method nor the values input into it are static, does anyone know why this is happening?

Method I’m trying to call:

    public void SpawnGameObject(Vector3 position)
    {
        Instantiate(spawnProjectile, position, Quaternion.identity);
        rb.AddForce(new Vector2(0, projectileSpeed));
    }

Code calling the method:

        if(Input.GetMouseButton(0) && shotCD <= 0)
        {
            SpawnProjectile.SpawnGameObject(transform.position);
            shotCD = startShotCD;
        }

Any help is greatly appreciated :)

Line 3, second block: that is an ATTEMPT to use SpawnGameObject as if it was static. It’s not static so that fails.

Instead, either 1) get a reference to the SpawnProjectile instance you need, or else 2) convert SpawnGameObject into a factory pattern static, something like this:

Factory Pattern in lieu of AddComponent (for timing and dependency correctness):