Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using System.Collections;
using UnityEngine;
using System;
public class DistancePowerGlove : IComparer
{
// Compares the distance between transforms, and this is called from "Sense Power GLOVE" to sort an array of colliders transforms.
private Transform compareTransform;
public DistancePowerGlove(Transform compTransform)
{
compareTransform = compTransform;
}
public int Compare(object x, object y)
{
Collider xCollider = x as Collider;
Collider yCollider = y as Collider;
Vector3 offset = xCollider.transform.position - compareTransform.position;
float xDistance = offset.sqrMagnitude;
offset = yCollider.transform.position - compareTransform.position;
float yDistance = offset.sqrMagnitude;
return xDistance.CompareTo(yDistance);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment