I wrote the code differently is that ok?

    private Transform GetClosest(Transform transformA, Transform transformB)
    {
        var distToA = Vector3.Distance(transform.position, transformA.position);
        var distToB = Vector3.Distance(transform.position, transformB.position);
        if (distToB < distToA)
        {
            transformA = transformB;
        }
        var finalTransford = transformA;
        return finalTransford;
    }

Hi,

Good job on challenging yourself by writing your own code. Did you test your it? Does it work? If so, it’s a solution. :slight_smile:


See also:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms