12345678910111213141516171819202122232425 |
- using UnityEngine;
- using System.Collections;
- using System;
- public class CompareXMonoBehaviour : MonoBehaviour, IComparable
- {
- public int CompareTo(object obj)
- {
- CompareXMonoBehaviour other = (CompareXMonoBehaviour)obj;
- //for descending order
- float otherPosX = other.transform.position.x;
- float posX = transform.position.x;
- if (otherPosX == posX)
- {
- return 0;
- } else
- if (otherPosX - posX < 0)
- {
- return -1;
- } else
- {
- return 1;
- }
- }
- }
|