UIEnemyPointController.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.SceneManagement;
  4. public class UIEnemyPointController : MonoBehaviour
  5. {
  6. private void OnEnable()
  7. {
  8. SceneManager.sceneUnloaded += this.OnSceneUnloaded;
  9. }
  10. private void Start()
  11. {
  12. }
  13. private void Update()
  14. {
  15. if (this.enemy == null)
  16. {
  17. NGUITools.Destroy(base.gameObject);
  18. return;
  19. }
  20. this.enemyPosition = Camera.main.WorldToViewportPoint(this.enemy.transform.position).x;
  21. NGUITools.SetActive(this.point.gameObject, this.enemyPosition < 0f || this.enemyPosition > 1f);
  22. if (this.enemyPosition < 0f)
  23. {
  24. this.point.transform.localScale = new Vector3(-1f, 1f, 1f);
  25. this.point.transform.localPosition = new Vector3((float)(-(float)UITools.ScreenWidth + 256), 1f / (this.enemyPosition / 100f - 2f / (float)UITools.ScreenHeight));
  26. }
  27. if (this.enemyPosition > 1f)
  28. {
  29. this.enemyPosition -= 1f;
  30. this.point.transform.localScale = Vector3.one;
  31. this.point.transform.localPosition = new Vector3((float)(UITools.ScreenWidth - 256), 1f / (-this.enemyPosition / 100f - 2f / (float)UITools.ScreenHeight));
  32. }
  33. if (this.enemy.currentHp <= 0)
  34. {
  35. NGUITools.Destroy(base.gameObject);
  36. }
  37. }
  38. private void OnDisable()
  39. {
  40. SceneManager.sceneUnloaded -= this.OnSceneUnloaded;
  41. }
  42. private void OnSceneUnloaded(Scene arg0)
  43. {
  44. NGUITools.Destroy(base.gameObject);
  45. }
  46. [SerializeField]
  47. private UISprite point;
  48. [SerializeField]
  49. public EnemyAttribute enemy;
  50. [SerializeField]
  51. private float enemyPosition;
  52. }