TransportButton.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class TransportButton : MonoBehaviour
  6. {
  7. [SerializeField]
  8. private Image imageButton;
  9. [SerializeField]
  10. private Button transportButton;
  11. Transform location;
  12. void LateUpdate ()
  13. {
  14. if (location != null)
  15. {
  16. if (imageButton!=null)
  17. {
  18. imageButton.enabled = true;
  19. transportButton.enabled = true;
  20. }
  21. if (Camera.main != null)
  22. {
  23. transform.position = Camera.main.WorldToScreenPoint(location.position);
  24. }
  25. }
  26. else
  27. {
  28. if (imageButton != null)
  29. {
  30. imageButton.enabled = false;
  31. transportButton.enabled = false;
  32. }
  33. }
  34. }
  35. public void Activate(Transform location)
  36. {
  37. gameObject.SetActive(true);
  38. this.location = location;
  39. }
  40. public void Deactivate()
  41. {
  42. gameObject.SetActive(false);
  43. }
  44. }