日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Unity_塔防游戏按波产生怪_063

發(fā)布時間:2023/12/20 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Unity_塔防游戏按波产生怪_063 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

怪物預制體上綁定的腳本:

using UnityEngine; using System.Collections; using System; public class NavigationFixedPath : MonoBehaviour {//保存所有的路點信息GameObject[] pathPoints;//記錄下一個路點int nextPathPointIndex = 1;// Use this for initializationvoid Start () {//通過tag值來獲取所有的路點pathPoints = GameObject.FindGameObjectsWithTag("Path01");//對獲取的路點排序//Array.Reverse(pathPoints);Array.Sort(pathPoints, (x, y) => { return x.gameObject.name.CompareTo(y.gameObject.name); });//產(chǎn)生的怪物放在第一個節(jié)點上transform.position = pathPoints[0].transform.position;//在第一個節(jié)點時,怪物的朝向transform.forward = pathPoints[nextPathPointIndex].transform.position - transform.position;}// Update is called once per framevoid Update () {if (Vector3.Distance(pathPoints[nextPathPointIndex].transform.position, transform.position) < 0.1f){//如果還有下一個節(jié)點就讓nextPathPointIndex自加if (nextPathPointIndex != pathPoints.Length - 1){nextPathPointIndex++;}//如果怪物自身的位置信息和最后一個節(jié)點的距離小于0.1m的時候if (Vector3.Distance(pathPoints[pathPoints.Length - 1].transform.position, transform.position) < 0.1f){//把最后一個節(jié)點的位置信息賦值給怪物自身的位置信息transform.position = pathPoints[pathPoints.Length - 1].transform.position;return;}//每次更換節(jié)點的時候改變怪物的位置信息transform.forward = pathPoints[nextPathPointIndex].transform.position - transform.position;}//怪物移動的邏輯transform.Translate(Vector3.forward * 5 * Time.deltaTime, Space.Self);} }

生成預制體腳本:

using UnityEngine; using System.Collections;public class CreateEnemeies : MonoBehaviour {//每一產(chǎn)生一個的計時器float timer = 0;//每一波產(chǎn)生的計時器float timer2 = 0;//產(chǎn)生敵人的速率public float rate;//敵人的預制體public GameObject enemeyPrefab;//每一波的時間public float timesofEachWave = 30;//每一波的已經(jīng)產(chǎn)生的數(shù)量private int count;// Use this for initializationvoid Start () {}// Update is called once per framevoid Update () {timer2 += Time.deltaTime;//每隔一定時間產(chǎn)生一波敵人if (timer2 < timesofEachWave && count!=10){timer += Time.deltaTime;//每隔一定的時間產(chǎn)生一個波敵人if (timer > rate){Instantiate(enemeyPrefab, Vector3.zero, Quaternion.identity);count++;timer -= rate;}}//如果每一波產(chǎn)生的時間大于timesofEachWave秒 if (timer2>timesofEachWave){timer2 -= timesofEachWave;//當前的數(shù)量清零count = 0;}} }

總結(jié)

以上是生活随笔為你收集整理的Unity_塔防游戏按波产生怪_063的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。