ToolTipsController.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class ToolTipsController : MonoBehaviour
  5. {
  6. public Camera mainCamera;
  7. private TextMesh tipsText;
  8. public bool isActive;
  9. public void Awake()
  10. {
  11. mainCamera = Camera.main;
  12. if (mainCamera == null)
  13. {
  14. mainCamera = GameObject.FindObjectOfType<Camera>();
  15. }
  16. tipsText = this.transform.GetComponentInChildren<TextMesh>();
  17. }
  18. private void Update()
  19. {
  20. if (!isActive) return;
  21. Vector3 dir = (mainCamera.transform.position - this.transform.position).normalized;
  22. this.transform.forward = new Vector3(dir.x, 0, dir.z);
  23. }
  24. public void Active()
  25. {
  26. isActive = true;
  27. tipsText.gameObject.SetActive(true);
  28. }
  29. public void DisActive()
  30. {
  31. isActive = false;
  32. tipsText.gameObject.SetActive(false);
  33. }
  34. public void ResetInfo(string tips, Transform targetPos)
  35. {
  36. this.transform.position = targetPos.transform.position;
  37. tipsText.text = tips;
  38. }
  39. }