Physics Raycast not working

My english is bad Im sorry :frowning:

Hi everyone, I make a building system. But it is not working. If I’m enable collider gameobject is come towards camera. But if I’m disable collider system is working but not colliding with walls or other gameobejcts.

My video: raycast not working - YouTube

 public float grid = 0.25F;
    public GameObject anlikItem;
    public Material green;
    public Material red;
    public Material defaultMaterial;
    public bool isBuildMode;
    public float degree = 90;
 
    void Update () {
        
        if (isBuildMode)
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                if (anlikItem.GetComponent<DekorItem>().isInterior)
                {
                    if (Input.GetButtonDown("Click"))
                    {

                        float x = Mathf.Round(hit.point.x / grid) * grid;
                        float z = Mathf.Round(hit.point.z / grid) * grid;
                        anlikItem.transform.position = new Vector3(x, hit.point.y, z);
                        anlikItem.GetComponent<Renderer>().material = defaultMaterial;
                        anlikItem.GetComponent<BoxCollider>().enabled = true;
                        anlikItem.GetComponent<NavMeshObstacle>().enabled = true;
                        isBuildMode = false;

                    }
                    else
                    {

                        anlikItem.GetComponent<Renderer>().material = green;

                    }
                }
                else
                {
                    anlikItem.GetComponent<Renderer>().material = red;
                }
                if (Input.GetButtonDown("Rotate"))
                {
                    anlikItem.transform.Rotate(Vector3.up, degree);
                }
                anlikItem.transform.position = new Vector3(Mathf.Round(hit.point.x / grid) * grid, hit.point.y, Mathf.Round(hit.point.z / grid) * grid);
            }
            
        }      
	}

    //Button clicked event..
    public void SetBuildModeTrue()
    {
        anlikItem = Instantiate(GameObject.Find("Control").GetComponent<Control>().selectedItem);        
        anlikItem.SetActive(true);
        defaultMaterial = anlikItem.GetComponent<DekorItem>().defaultMat;
        isBuildMode = true;
    }

The problem is the anlikItem object’s collider: as soon as the object is created, the raycast hits it instead of the ground, and the grid system makes the object be positioned closer to the camera update after update.
There are two main solutions, both in SetBuildModeTrue():

1- Place the object in the Ignore Raycast layer (layer 2 - default layer is 0):

...
     defaultMaterial = anlikItem.GetComponent<DekorItem>().defaultMat;
     anlikItem.layer = 2; // place object in Ignore Raycast layer
     isBuildMode = true;
 }

2- Or make sure the collider is disabled:

...
     defaultMaterial = anlikItem.GetComponent<DekorItem>().defaultMat;
     anlikItem.GetComponent<BoxCollider>().enabled = false; // disable object's collider
     isBuildMode = true;
 }

Please help me :frowning: