FollowWorldPosition.cs 979 B

1234567891011121314151617181920212223242526272829303132333435
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Sirenix.OdinInspector;
  5. namespace KairoEngine.Inventory
  6. {
  7. public class FollowWorldPosition : MonoBehaviour
  8. {
  9. public ItemContainerUi ItemContainerUi;
  10. public GameObject panel;
  11. public float yDistance = 2;
  12. private Transform target;
  13. void OnEnable()
  14. {
  15. }
  16. void Update()
  17. {
  18. if(panel.activeSelf)
  19. {
  20. target = ItemContainerUi.targetItemContainer.transform;
  21. if(target != null)
  22. {
  23. Vector3 pos = new Vector3(target.position.x, target.position.y + yDistance, target.position.z);
  24. Vector3 screenPos = Camera.main.WorldToScreenPoint(pos);
  25. screenPos.z = 100;
  26. panel.GetComponent<RectTransform>().position = screenPos;
  27. }
  28. }
  29. }
  30. }
  31. }