123456789101112131415161718192021222324252627282930313233343536373839404142 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class ToolTipsController : MonoBehaviour
- {
- public Camera mainCamera;
- private TextMesh tipsText;
- public bool isActive;
- public void Awake()
- {
- mainCamera = Camera.main;
- if (mainCamera == null)
- {
- mainCamera = GameObject.FindObjectOfType<Camera>();
- }
- tipsText = this.transform.GetComponentInChildren<TextMesh>();
- }
- private void Update()
- {
- if (!isActive) return;
- Vector3 dir = (mainCamera.transform.position - this.transform.position).normalized;
- this.transform.forward = new Vector3(dir.x, 0, dir.z);
- }
- public void Active()
- {
- isActive = true;
- tipsText.gameObject.SetActive(true);
- }
- public void DisActive()
- {
- isActive = false;
- tipsText.gameObject.SetActive(false);
- }
- public void ResetInfo(string tips, Transform targetPos)
- {
- this.transform.position = targetPos.transform.position;
- tipsText.text = tips;
- }
- }
|