UNITY_生成器代码

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class generator : MonoBehaviour
{
    public GameObject cylinderPrefab;//是公开的游戏对象字段,表示预设的圆柱体对象。
    public Transform coordinate;//公开的变换对象,将用于设定新生成物体的位置。
    public float interval = 1.0f;//控制生成圆柱体之间的间隔时间。
    public Vector3 rotation;// 公开的旋转信息,设置新生成的圆柱体初始的朝向。
    // Start is called before the first frame update
    void Start()//开始函数,在游戏开始前被调用,这里启动了一个Coroutine (StartCoroutine(spawn())) 进行物体生成。
    {
        StartCoroutine(spawn());
    }

    // Update is called once per frame
    IEnumerator spawn()//是一个异步迭代器,用于生成过程的控制流。它会持续运行,并在每次yield return后暂停。
    {
        while (true)//创建了一个无限循环,除非外部干预,否则不会停止。
        {
            GameObject spawnObject =  Instantiate(cylinderPrefab, coordinate.position, Quaternion.identity);
            //在当前位置和正方向(即四元数Quaternion.identity)创建一个新的圆柱体实例。
            spawnObject.transform.eulerAngles = rotation;//设置新生成圆柱体的朝向为rotation。
            yield return new WaitForSeconds(interval);// 暂停当前函数,等待指定的秒数,然后继续下一轮循环。
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值