1、准备工作
(1) 将素材图片 添加到Assets
(2) 制作预制体,名字自取。如Tray
(3) 在Tray预制体上添加Tray.cs组件
2、编写代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Tray : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
StartCoroutine(DestroyTray());
//启动一个名为DestroyObjectEveryHalfSecond的协程
//StartCoroutine需要通过关键字“yield”实现
}
IEnumerator DestroyTray()
{
while (true)
{
yield return new WaitForSeconds(0.6f);
// 等待0.6秒,回到新的0.6秒(每间隔0.6秒,就执行)
Destroy(gameObject); // 销毁物体
}
}
// Update is called once per frame
void Update()
{
}
}
(4)