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

61 lines
1.7 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;
private Transform promptpos;
private float movedistance = 400f;//<2F>ƶ<EFBFBD><C6B6>ľ<EFBFBD><C4BE><EFBFBD>
private float moveDuration = 1f;//<2F>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
// Start is called before the first frame update
void Start()
{
Instance = this;
DontDestroyOnLoad(this);
PromptPrefab = (GameObject)Resources.Load("Prefabs/Prompt");
}
public void PromptBubble(string message)
{
GameObject proobj = Instantiate(PromptPrefab);
proobj.transform.SetParent(GameObject.Find("Canvas").transform);
proobj.transform.position = new Vector3(540, 1300, 0);
StartCoroutine(MoveUpandDestory(proobj));
Text protext = proobj.transform.Find("Prompttext").GetComponent<Text>(); ;
protext.text = message;
}
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 11:28:49 +08:00
yield return new WaitForSeconds(0.3f); // <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>
}
}