CompareXMonoBehaviour.cs 468 B

12345678910111213141516171819202122232425
  1. using UnityEngine;
  2. using System.Collections;
  3. using System;
  4. public class CompareXMonoBehaviour : MonoBehaviour, IComparable
  5. {
  6. public int CompareTo(object obj)
  7. {
  8. CompareXMonoBehaviour other = (CompareXMonoBehaviour)obj;
  9. //for descending order
  10. float otherPosX = other.transform.position.x;
  11. float posX = transform.position.x;
  12. if (otherPosX == posX)
  13. {
  14. return 0;
  15. } else
  16. if (otherPosX - posX < 0)
  17. {
  18. return -1;
  19. } else
  20. {
  21. return 1;
  22. }
  23. }
  24. }