Cannot be accessed with an instance reference; qualify it with a type name instead?

Hello there I am a beginner user
So I was trying to make a pickup code. without the “CurrentObject.constraints.FreezeRotation = false;”
It was working as intended, but I want to lock the rotation physic object that has been picked up. but, I got this error instead: Member ‘RigidbodyConstraints.FreezeRotation’ cannot be accessed with an instance reference; qualify it with a type name instead. How can I fix this? Thank you

using System.Collections;
using UnityEngine.InputSystem;
using UnityEngine;
namespace StarterAssets

{
public class PickupScript : MonoBehaviour
{
    [SerializeField] private LayerMask PickupMask;
    [SerializeField] private Camera PlayerCam;
    [SerializeField] private Transform PickupTarget;
    [Space]
    [SerializeField] private float PickupRange;
    private Rigidbody CurrentObject;


        void Start()
        {
            animator = GetComponent<Animator>();
        }
    public void OnInteraction(InputValue value)
    {
        {
            if(CurrentObject)
            {
                CurrentObject.useGravity = true;
                CurrentObject = null;
                [I]CurrentObject.constraints.FreezeRotation = true;[/I]
                return;
            }

            Ray CameraRay = PlayerCam.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f));
            if (Physics.Raycast(CameraRay, out RaycastHit HitInfo, PickupRange, PickupMask))
            {
                CurrentObject = HitInfo.rigidbody;
                CurrentObject.useGravity = false;
                [I]CurrentObject.constraints.FreezeRotation = true;[/I]
                }
        }
    }

    void FixedUpdate()
    {
        if(CurrentObject)
        {
            Vector3 DirectionToPoint = PickupTarget.position - CurrentObject.position;
            float DistanceToPoint = DirectionToPoint.magnitude;
            CurrentObject.velocity = DirectionToPoint * 12f * DistanceToPoint;
        }
    }
}

Console:
PickupScript.cs(41,17): error CS0176: Member ‘RigidbodyConstraints.FreezeRotation’ cannot be accessed with an instance reference; qualify it with a type name instead

If you want to freeze the rotation, you need to follow how to do it. Unity - Scripting API: RigidbodyConstraints

Looks like if you want to freeze rotation, you actually need to do.

CurrentObject.constraints = RigidbodyConstraints.FreezeRotation;
1 Like