'How to set Tiles in a 3D Tilemap?

I have a problem. I'm trying to create a system where you can place tiles on a tilemap with your mouse. I recently switched my project from 2D to 3D. Is there any way I could add a tile(gameobject) to the tilemap in 3d? heres my code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Tilemaps;

public class PlaceTiles : MonoBehaviour
{
    public Tilemap tileMap;
    public Tile grass;
    private RaycastHit hit;
    private Vector3Int hitPoint;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
        RaycastHit2D hit = Physics2D.Linecast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);

        if (hit.collider != null && Input.GetMouseButton(0))
        {
            Vector3Int hitPoint = Vector3Int.FloorToInt(hit.point);
            tileMap.SetTile(hitPoint, grass);
        }

    }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source