Unity实现方圆X范围随机生成怪物

编程入门 行业动态 更新时间:2024-10-28 01:27:17

Unity实现<a href=https://www.elefans.com/category/jswz/34/1674663.html style=方圆X范围随机生成怪物"/>

Unity实现方圆X范围随机生成怪物

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class CreatMonster : MonoBehaviour
{// S这个脚本间隔一点时间生成怪物/*1.程序逻辑* 1. 设计一个计时器* 2.间隔一段时间3s执行一下     * */float SaveTime = 0f;public GameObject OneMonsterPre;public Transform MonsterCenterPOS;float CloneX;float CloneZ;// Update is called once per framevoid Update(){SaveTime += Time.deltaTime;if (SaveTime>=3){Debug.Log("时间超过3秒");SaveTime = 0;CloneMonster();}}//endupdatevoid CloneMonster(){Debug.Log("生成随机数");for (int i = 0; i < 10; i++){CloneX = Random.Range(1f, 100f) + MonsterCenterPOS.position.x;CloneZ = Random.Range(1f, 300f) + MonsterCenterPOS.position.z;Vector3 TempPos = new Vector3(CloneX, MonsterCenterPOS.position.y, CloneZ);Debug.Log("随机坐标" + TempPos);GameObject TempOBJ=  GameObject.Instantiate(OneMonsterPre, TempPos, Quaternion.Euler(new Vector3(Random.Range(10, 80), 0, Random.Range(10, 80))));Destroy(TempOBJ,3f);}  }
}//endclass

 

更多推荐

Unity实现方圆X范围随机生成怪物

本文发布于:2023-12-06 04:11:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1666397.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方圆   怪物   Unity

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!