ToastSysterm.ts 570 B

12345678910111213141516171819202122
  1. import { _decorator, Component, instantiate, Label, Node } from 'cc';
  2. const { ccclass, property } = _decorator;
  3. @ccclass('ToastSysterm')
  4. export class ToastSysterm extends Component {
  5. @property(Node)
  6. item: Node = null
  7. showToast(content: string, time: number = 2){
  8. const toast = instantiate(this.item)
  9. toast.getComponentInChildren(Label).string = content
  10. toast.active = true
  11. this.node.addChild(toast)
  12. this.scheduleOnce(()=>{
  13. toast.removeFromParent()
  14. toast.destroy()
  15. }, time)
  16. }
  17. }