How do i rotate an object towards mouse?

So basically I’m making a game with a stickman that can pick up stuff. I added guns and made pickable items. The gun is attached to the hand of the stickman which follows the mouse cursor. The problem is the gun doesn’t rotate as the hand goes right and it flips 180 degrees. I’m really a beginner so i don’t really know much. Would appreciate some help! :slight_smile:

Please attach your code so we can help you out

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

public class EquipManager : MonoBehaviour
{
    private Dictionary<BodyPartType, BodyPart> bodyParts = new Dictionary<BodyPartType, BodyPart>();
    public List<Item> inventory = new List<Item>();

    public Equipable starting_item;

    public Limb handL;
    Camera cam;

    private bool holding;

    void Start()
    {   
        holding = false;
        BodyPart[] get_parts = transform.GetComponentsInChildren<BodyPart>();
        foreach(var part in get_parts) {
            bodyParts.Add(part.type, part);
        }
        EquipItem(starting_item);

        cam = Camera.main;

    }

    void Pickup(Pickable pick) {
        if(!pick) 
           return;
         
        
        
        var item = pick.item;

        if(item.GetType() == typeof(Equipable)) {
         EquipItem((Equipable)item);
        } else {
         inventory.Add(item);

        }
        pick.PickUp();
    
    }
    
    void EquipItem(Equipable item) {
        if(!item)
           return;
        if(bodyParts.TryGetValue(item.type, out var part)) {
            part.Equip(item);
            // if(handL.transform.rotation.z == 170) {
            //  item.transform.Rotate(0, 180, 0);
            // }
        }
    }

   

    
    void Update()
    {
        if(Input.GetKeyDown(KeyCode.G)) {
           Pickup(Pickable.GetItem(transform.position, 10));
            holding = true;
        }

          if(holding) {
             var dir = cam.ScreenToWorldPoint(Input.mousePosition) - transform.position;
            //handR.setPosition(dir, 2.5f);
            handL.setPosition(dir, 2.5f);
         }
    }
}

basically what i tried is
if(handL.transform.rotation.z == 170) {
item.transform.Rotate(0, 180, 0);
{

@unity_ek98vnTRplGj8Q