ImageToggler.cs 736 B

1234567891011121314151617181920212223242526272829303132333435
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.UI;
  4. namespace Devdog.SciFiDesign.UI
  5. {
  6. public class ImageToggler : MonoBehaviour
  7. {
  8. public Sprite spriteA;
  9. public Sprite spriteB;
  10. public Color colorA;
  11. public Color colorB;
  12. private Image _image;
  13. protected void Awake()
  14. {
  15. _image = GetComponent<Image>();
  16. }
  17. public void Toggle()
  18. {
  19. if (_image.sprite == spriteA)
  20. {
  21. _image.sprite = spriteB;
  22. _image.color = colorB;
  23. }
  24. else
  25. {
  26. _image.sprite = spriteA;
  27. _image.color = colorA;
  28. }
  29. }
  30. }
  31. }