duck

duck

Aug 10th, 2010
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.58 KB | None | 0 0
  1.  
  2. static Tip[] tips;
  3.  
  4. public class Tip : MonoBehaviour
  5. {
  6.     public void Start()
  7.     {
  8.         if (tips == null)
  9.         {
  10.             tips = (Tip[]) FindObjectsOfType(typeof(Tip));
  11.             System.Array.Sort(tips, new TipComparer());
  12.         }
  13.        
  14.         Debug.Log("Tips sorted in this order:");
  15.         foreach (Tip tip in tips)
  16.         {
  17.             DebugX.Log("  - "+tip.name);
  18.         }
  19.    
  20.     }
  21. }
  22.  
  23.  
  24.  
  25. public class TipComparer : IComparer<Tip>
  26. {
  27.     public int Compare (Tip a, Tip b)
  28.     {
  29.         if (a.transform.position.x > b.transform.position.x) {
  30.             return 1;
  31.         } else {
  32.             return -1;
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment