123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class SceneCmptBubbleWindow : MonoBehaviour
- {
- public string text = "";
- public bool isAuto = false;
- GameObject bg;
- GameObject frame;
- Text content;
- float liveTime = 3.0f;
- float curTime = 0;
- bool isEnable = false;
-
- private void Awake()
- {
- bg = this.transform.Find("bg").gameObject;
- frame = this.transform.Find("frame").gameObject;
- content = this.transform.Find("Canvas/Text").GetComponent<Text>();
- content.text = text;
- curTime = 0;
- Hide();
- }
- // Start is called before the first frame update
- void Start()
- {
- }
- // Update is called once per frame
- void Update()
- {
- if(!isEnable)
- {
- return;
- }
- curTime += Time.deltaTime;
- if(curTime > liveTime)
- {
- GameObject.Destroy(this.gameObject);
- }
- }
- public void SetContent(string str)
- {
- text = str;
- content.text = text;
- isEnable = true;
- Show();
- }
- public void Show()
- {
- this.bg.SetActive(true);
- this.frame.SetActive(true);
- this.content.gameObject.SetActive(true);
- }
- public void Hide()
- {
- this.bg.SetActive(false);
- this.frame.SetActive(false);
- this.content.gameObject.SetActive(false);
- }
- public void OnTriggerEnter(Collider other)
- {
- if(isAuto && other.gameObject.layer == LayerMask.GetMask("Player"))
- {
- SetContent(this.text);
- }
- }
- }
|