场景中挂载生成鱼的脚本
鱼生成的脚本
using UnityEngine;
using System.Collections;
public class FishMaker : MonoBehaviour {
public Transform fishHolder;//存放鱼的节点
public Transform[] genPositions;//所有的鱼的Transform
public GameObject[] fishPrefabs;//所有鱼的预设
public float waveGenWaitTime = 0.3f;//每波生成间隔的时间
public float fishGenWaitTime = 0.5f;//每条鱼之间生成的间隔
void Start () {
InvokeRepeating("MakeFishes", 0, waveGenWaitTime);//循环生成鱼
}
//生成本批次鱼
void MakeFishes()
{
int genPosIndex = Random.Range(0, genPositions.Length);//随机一个起点
int fishPreIndex = Random.Range(0, fishPrefabs.Length);//随机一条鱼
int maxNum = fishPrefabs[fishPreIndex].GetComponent<FishAttr>().maxNum;//获取本批鱼最大的数量
int maxSpeed = fishPrefabs[fishPreIndex].GetComponent<FishAttr>().maxSpeed