Advertisement
NPSF3000

OnCooperative

Feb 21st, 2013
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.96 KB | None | 0 0
  1. //Need two components to work together, with only one actually doing the 'work'?
  2. //E.g.  two audio scripts that only want to play 1 sound on collision.
  3. //Just use the following Pseudo Code
  4.  
  5. //OnCollision:
  6. //audio.OnCooperative(other.audio, () => audio.PlaySound("Bazinga!"));
  7.  
  8. using UnityEngine;
  9. using System;
  10. using System.Collections.Generic;
  11.  
  12. public static class Helper
  13. {
  14.     /*public static int Counter = 0;
  15.     public static Dictionary<Component, int> coop = new Dictionary<Component, int>();
  16.  
  17.     public static void OnCooperative(this Component first, Component second, Action action)
  18.     {
  19.         if (!coop.ContainsKey(first)) coop[first] = Counter++;
  20.         if (!coop.ContainsKey(second)) coop[second] = Counter++;
  21.         if (coop[first] > coop[second]) action();
  22.     }*/
  23.  
  24.     public static void OnCooperative(this Component first, Component second, Action action)
  25.     {
  26.         if (first.GetInstanceID() > second.GetInstanceID()) action();
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement