Created
October 4, 2020 15:45
-
-
Save vallentiin/04cc7f7a7c4ef62474e035c71289baf8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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