噩梦系列篇其他敌人制作与敌人自动生成功能

来源:互联网 发布:淘宝网哪家男装最潮 编辑:程序博客网 时间:2024/04/20 05:28

其他的敌人制作跟我们之前所做的一样,把各种脚本添加给新的敌人素材,如下图的各种面板里的各种属性脚本等。然后把他们都做成perfabs。。。。


敌人自动生成的功能很是简单。

首先建立几个空的gameobject然后重新命名,之后给他们贴好标签。如图;游戏里有三种敌人,所以这里就做三种spawn用来分别生成不同类的敌人。。



老规矩,让我们coding起来:

把这个脚本加入到这些Spawn就可。代码中的public GameObject enemys;这里是public所以,最后只要把对应的perfab拖到这里就可以了。

using UnityEngine;using System.Collections;public class spawn : MonoBehaviour {    public GameObject enemys;       void Start () {        InvokeRepeating("spawnenemy", 1, 13);        InvokeRepeating("spawnbnny", 1, 10);        InvokeRepeating("spawnelephant", 1, 33);        }// Update is called once per framevoid Update () {      }    void spawnbear()    {        GameObject.Instantiate(enemys, transform.position, transform.rotation);//生成敌人    }    void spawnbnny()    {        GameObject.Instantiate(enemys, transform.position, transform.rotation);    }    void spawnelephant()    {        GameObject.Instantiate(enemys, transform.position, transform.rotation);    }}

至此敌人的生成已经完成。。。所有核心功能全部完成。

************************************************************************************************************

当然还有一种常用的方法来生成敌人;这种就是弄个计时器.。这次就让生成的敌人越来越快。把spawntime一直减小就ok;

代码如下:



using UnityEngine;using System.Collections;public class enemynewspawn : MonoBehaviour {    public GameObject enemyss;    private float spawntime=3f;    private float timer;        void timereduce()    {        spawntime -= 0.05f;//生成时间越来愈快        }// Update is called once per framevoid Update () {        timer -= Time.deltaTime;        if (timer <= 0)        {            spawn();            timereduce();            timer = spawntime;                   }        }    void spawn()    {        GameObject.Instantiate(enemyss, transform.position, transform.rotation);    }}
至此敌人的生成已经完成。。。所有核心功能全部完成。

0 0
原创粉丝点击