2D 敌人生成 特效播放

来源:互联网 发布:来电闪光灯软件 编辑:程序博客网 时间:2024/04/19 14:46
using UnityEngine;using System.Collections;public class Spawner : MonoBehaviour {    public float spawnTime =5f;//每个敌人产生的时间间隔    public float spawnDelay = 3f;//敌人产生开始前的时间。    public GameObject[] enemies;//敌人预设的数组    // Use this for initialization    void Start () {        //在延迟一段时间后反复调用Spawn函数        InvokeRepeating("Spawn", spawnDelay, spawnTime);    }    void Spawn(){        //实例化一个随机敌人        int enemyIndex = Random.Range (0, enemies.Length);        Instantiate (enemies [enemyIndex], transform.position, transform.rotation);        //播放子物体中所有粒子特效        foreach(ParticleSystem p in GetComponentsInChildren<ParticleSystem>())        {            p.Play();        }    }}
0 0
原创粉丝点击