Getting TKey by comparing TValue with extra factor using Dictionary

Vector3 m_cursorOrigin =;
Dictionary<GameObject, float> m_targetDictionary = new Dictionary<GameObject, float>();

Public void SwitchTargetMouseDirection(Vector3 inputDir)
    // This actually happens in another method with buttonDown input event, but brought here just to clarify
    Vector3 mPos = Input.mousePosition;
    mPos = Camera.main.ScreenToWorldPoint(new Vector3(mPos.x, mPos.y, 0));
    mPos.z = 0;
    m_cursorOrigin.Position = mPos;    

    float inputAnle = Quaternion.FromToRotation(Vector3.up, inputDir - m_cursorOrigin.position).eulerAngles.z;
    var bestMatchByAnle = m_targetDcitionary.Aggregate((l, r) => l.value > r.Value ? l : r);


Is what I've done so far.

What I'm trying to do is get inputAngle to be able to compare TValues in m_targetDictionary, which in its TValue holds the angle from an origin point in world as float, and get the TKey of that result. In other words, I'm trying to be able to flick my mouse in a direction(when m_cursorOrigin is set) and find a target GameObject: It could be like a radial menu, but that'd be a radial menu with multiple layers of radials stacked. I'm aware that the distance should be another factor along with angle I'm trying to compare, but I think I need to focus on one first.

As shown in the code block I could only get myself to compare TValues within itself by Googling. I admit, linq is tough to absorb for a novice like me. I'm not bound to use linq to achieve this. Anything does the job I'll take it, and this portion of my tasks has dragged me more than long enough by now. Can I get some help?

Edit by Progress :

Vector3 m_cursorOrigin =;
Dictionary<GameObject, float> m_targetDictionary = new Dictionary<GameObject, float>();

private void SwitchTargetMouseDirection(Vector3 inputDir)
    float inputAngle = Quaternion.FromToRotation(Vector3.up, inputDir - m_cursorOrigin.position).eulerAngles.z;
    var bestMatch = m_collector.m_targetDictionary.OrderBy(e => Mathf.Abs(e.Value - inputAngle)).FirstOrDefault();

    m_target = bestMatch.Key;

I've somewhat achieved progress. However, I'm pretty sure I'm not getting wrong values out somewhere; by this I mean either one of this comparison floats is not what it shows. I think I know where to look and this is my current priority.

Anyways, the question also progresses from here.

Now that I've got one exterior factor to compare values within Dictionary to pick out a TKey of its match I'd like another thing happening along with it which is compare 'again' by distance. I'm pretty lost even where to start with this, but my guess is that I need to sort out groups of those similar values above within certain range instead of just a solitary key output. And then sort out by the distance from there. I've got no comments so far on this. Help..?