Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5. using UnityEngine.Events;
  6. [RequireComponent(typeof(Collider2D))]
  7. public class OnTrigger : MonoBehaviour {
  8.  
  9. // Use this for initialization
  10. public UnityEvent enter;
  11. public UnityEvent exit;
  12. public bool cat = true;
  13. public bool dog = true;
  14. public bool boy = true;
  15.  
  16. public bool together = true;
  17. void OnTriggerEnter2D(Collider2D other)
  18. {
  19. if(other.gameObject.tag == "Player")
  20. {
  21. if(together
  22. &&
  23. (!cat || other.gameObject.name.Contains("Cat"))
  24. && (!dog || other.gameObject.name.Contains("Dog"))
  25. && (!boy || other.gameObject.name.Contains("Boy")))
  26. {
  27. enter.Invoke();
  28. }else if((!cat || other.gameObject.name.Contains("Cat"))
  29. ||(!dog || other.gameObject.name.Contains("Dog"))
  30. || (!boy || other.gameObject.name.Contains("Boy")))
  31. {
  32. enter.Invoke();
  33. }
  34.  
  35. }
  36. }
  37.  
  38. void OnTriggerExit2D(Collider2D other)
  39. {
  40. if(together
  41. &&
  42. (!cat || other.gameObject.name.Contains("Cat"))
  43. && (!dog || other.gameObject.name.Contains("Dog"))
  44. && (!boy || other.gameObject.name.Contains("Boy")))
  45. {
  46. exit.Invoke();
  47. }else if((!cat || other.gameObject.name.Contains("Cat"))
  48. ||(!dog || other.gameObject.name.Contains("Dog"))
  49. || (!boy || other.gameObject.name.Contains("Boy")))
  50. {
  51. exit.Invoke();
  52. }
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement