Cute_demon_attacks/meng_yao/Assets/script/Manager/Promptmgr.cs

72 lines
2.3 KiB
C#
Raw Normal View History

2024-10-28 10:57:19 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Promptmgr : MonoBehaviour
{
public static Promptmgr Instance;
private GameObject PromptPrefab;
2024-10-28 16:41:14 +08:00
private GameObject PromptWhiltePrefab;
2024-10-30 01:08:16 +08:00
private float movedistance = 800f;//<2F>ƶ<EFBFBD><C6B6>ľ<EFBFBD><C4BE><EFBFBD>
2024-10-28 10:57:19 +08:00
private float moveDuration = 1f;//<2F>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
// Start is called before the first frame update
void Start()
{
2024-10-30 01:33:31 +08:00
2024-10-28 10:57:19 +08:00
Instance = this;
DontDestroyOnLoad(this);
PromptPrefab = (GameObject)Resources.Load("Prefabs/Prompt");
2024-10-28 16:41:14 +08:00
PromptWhiltePrefab = (GameObject)Resources.Load("Prefabs/PromptWhite");
2024-10-28 10:57:19 +08:00
}
public void PromptBubble(string message)
{
GameObject proobj = Instantiate(PromptPrefab);
proobj.transform.SetParent(GameObject.Find("Canvas").transform);
2024-10-30 01:08:16 +08:00
proobj.transform.position =new Vector3(Screen.width/2,Screen.height/2+33,0);
2024-10-28 10:57:19 +08:00
StartCoroutine(MoveUpandDestory(proobj));
2024-10-29 12:01:30 +08:00
Text protext = proobj.transform.Find("Prompttext").GetComponent<Text>();
2024-10-28 10:57:19 +08:00
protext.text = message;
2024-10-29 12:01:30 +08:00
}
2024-10-28 10:57:19 +08:00
2024-10-28 16:41:14 +08:00
public void PromptWhilteBubble(string message)
{
GameObject proobj = Instantiate(PromptWhiltePrefab);
proobj.transform.SetParent(GameObject.Find("Canvas").transform);
2024-10-30 01:19:18 +08:00
proobj.transform.position = new Vector3(Screen.width / 2, Screen.height / 2 + 33, 0);
2024-10-28 16:41:14 +08:00
StartCoroutine(MoveUpandDestory(proobj));
Text protext = proobj.transform.Find("Prompttext").GetComponent<Text>(); ;
protext.text = message;
2024-10-28 10:57:19 +08:00
}
IEnumerator MoveUpandDestory(GameObject obj)
{
RectTransform uielement = obj.GetComponent<RectTransform>();
Vector3 startPosition = uielement.anchoredPosition;
Vector3 endPosition = startPosition + new Vector3(0, movedistance, 0);
float elapsedTime = 0f;
while (elapsedTime < moveDuration)
{
uielement.anchoredPosition = Vector3.Lerp(startPosition, endPosition, (elapsedTime / moveDuration));
elapsedTime += Time.deltaTime;
yield return null; // <20>ȴ<EFBFBD><C8B4><EFBFBD>һ֡
}
uielement.anchoredPosition = endPosition; // ȷ<><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>׼ȷ
// <20>ȴ<EFBFBD>һ<EFBFBD><D2BB>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2024-10-28 22:05:14 +08:00
yield return new WaitForSeconds(1f); // <20>ɵ<EFBFBD><C9B5><EFBFBD><EFBFBD>ĵȴ<C4B5>ʱ<EFBFBD><CAB1>
2024-10-28 10:57:19 +08:00
Destroy(uielement.gameObject); // <20><><EFBFBD><EFBFBD>UIԪ<49><D4AA>
}
}