How can i make the object follow mouse position

I want to make an object move in world using mouse position input, here is the code:

IEnumerator ThrowTrap(){

	Throwing = true;
	GameObject t = Instantiate (trap, transform.position + offset, Quaternion.identity);

	Camera c = Camera.main;
	Event e = Event.current;
	Vector2 mousePos = new Vector2 ();

	mousePos.x = e.mousePosition.x;
	mousePos.y = c.pixelHeight - e.mousePosition.y;

	Vector3 p = c.ScreenToWorldPoint(new Vector3(mousePos.x,mousePos.y,c.nearClipPlane));

	t.transform.Translate(p);

	yield return new  WaitForSeconds (trapDuration);
	Destroy (t.gameObject);
	yield return new WaitForSeconds (trapCooldown);
	Throwing = false;
}

Have a look at this link and perhaps this code. It’s not super clear what you are trying to accomplish or trying to get to move. Unity - Manual: Moving an Agent to a Position Clicked by the Mouse

// MoveToClickPoint.cs
    using UnityEngine;
    using UnityEngine.AI;
    
    public class MoveToClickPoint : MonoBehaviour {
        NavMeshAgent agent;
        
        void Start() {
            agent = GetComponent<NavMeshAgent>();
        }
        
        void Update() {
            if (Input.GetMouseButtonDown(0)) {
                RaycastHit hit;
                
                if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 100)) {
                    agent.destination = hit.point;
                }
            }
        }
    }