Unity3d Survival Shooter Tutorial 学习笔记(七)---生成敌人

!!一定要记得把ZomBear和Hellephant的Layer设置为 Shootable

(我说为啥他们打不死= = ,忘记设置shootable了)

1.添加另外一种enemy:Zombear。

由于Zombear和之前的Bunny有相同的骨骼、动画等,因此很多bunny的东西都可以复用

2.把Zombear设置成Prefabs,并把Zombear拖到Hierarchy上

3.之前写的EnemyAC可以再次用到Zombear上。

4.把Zombunny的其他属性复制粘贴到Zombear,包括Scripts

5.添加最后一种enemy:Elephant

为了避免重复设置之前的参数,这里我们使用:Animator override controller

你可以在游戏中创建一大堆角色不同的类,他们有相同的骨骼,可以用相同的状态机表示,只需要改变他们的动画即可。

命名为hellelphantAOC

把EnemyAC拖到hellelphantAOC的Controller里。

由于elephant和前面两种enemy有相同的动作逻辑,我们只需要改变不同动作的动画即可。把elephant对应的Death,Idle,Move拖到Override里头:

6.同理把elephent设置为prefabs(拖进Prefabs文件夹),把hellelphantAOC脱欧到elephant的Animator里:

7.同理,把Zombunny的其他属性复制粘贴到elephant,包括Scripts

8.建立一个EnemyManager(GameObject)用于生成并管理enemy,记得把位置reset到(0,0,0)

并添加脚本:

using UnityEngine;

public class EnemyManager : MonoBehaviour
{
    public PlayerHealth playerHealth;//在playerHealth>0时才生成enemy-
    public GameObject enemy;//任意一种enemy
    public float spawnTime = 3f;//这种enemy的生成时间间隔
    public Transform[] spawnPoints;//enmemy的生成位置


    void Start ()
    {
        InvokeRepeating ("Spawn", spawnTime, spawnTime);
    }


    void Spawn ()
    {
        if(playerHealth.currentHealth <= 0f)
        {
            return;
        }

        int spawnPointIndex = Random.Range (0, spawnPoints.Length);//随意选一个生成位置

        Instantiate (enemy, spawnPoints[spawnPointIndex].position, spawnPoints[spawnPointIndex].rotation);//生成enemy
    }
}

游戏从3个位置生成3种不同的enemy

为3种enemy添加SpawnPoint,并g给每种SpawnPoint添加颜色标记:

BunnySpawnPoint:

BearSpawnPoint:

HellephantSpawnPoint:

9.把3个SpawnPoint拖入3个EnemyManager.cs里

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Zombie Raid is a thrilling top-down shooter survival game set in a post-apocalyptic world overrun by zombies. The game features fast-paced action, challenging gameplay, and a variety of weapons and power-ups to help you survive. As a survivor, your goal is to protect your base from the endless waves of zombies. You'll need to use your wits and quick reflexes to stay alive and fend off the undead hordes. The game features a variety of weapons, from pistols and shotguns to assault rifles and rocket launchers, to help you take down the zombies. In addition to weapons, you can also collect power-ups like health kits, ammo crates, and special abilities to help you survive. These power-ups can be found scattered throughout the game world, so be sure to explore and scavenge as much as possible. Zombie Raid also features a variety of enemies, from slow-moving zombies to fast and agile ones, as well as bosses that require strategy and skill to defeat. You'll need to adapt to each new wave of enemies and use different tactics to survive. The game also features multiple levels, each with its own unique challenges and objectives. As you progress through the game, you'll unlock new weapons and abilities, making it easier to take on the hordes of zombies. Overall, Zombie Raid is a fun and exciting top-down shooter survival game that will keep you on the edge of your seat. With its challenging gameplay, variety of weapons and power-ups, and endless waves of zombies, it's a game that's sure to keep you entertained for hours on end.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值