在models/characters文件夹找到Zombunny
给Zombunny添加粒子系统
把Prefabs/HItPraticles拖到Zombunny
就像将Floor隔离为Floor Layer一样,Zombunny可以放到可射击层(Shootable Layer)
注意,environment也在Shootable Layer!
和Palyer一样,Zombunny也需要设置为Rigidbody
添加Capsule Collider
同时,我们还需要一个触发碰撞器,来检测Bunny是否和玩家发生了碰撞。
所以添加Sphere Collider,并把它设置为Trigger
Sphere 要比Capsule大,因为Bunny的手也会伤害到Player,设置为Trigger,一旦Bunny碰到Player就可以调用某一Script处理。
Navigation
让Bunny跟着Player
给Bunny添加Nav Mash Agent
使其能通过AI避开障碍物运动,并自动追踪目标
在Navigation中设置Bake参数:
由于我们有多个Agent(Bunny,elephant..)所以参数要满足所有Agent:
蓝色区域就是Agent可以到的区域
创建Enemy 动画--》Animator Controller: EnemyAC
默认状态设置为Move
设置两个参数PlayerDead和Dead
当PlayerDead时,Bunny状态由Move转到Idle
当Bunny Dead时,状态由Any State转到Death
为Bunny添加Script:EnemyMovement.cs
using UnityEngine;
using System.Collections;
public class EnemyMovement : MonoBehaviour
{
Transform player;
//PlayerHealth playerHealth;
//EnemyHealth enemyHealth;
UnityEngine.AI.NavMeshAgent nav;
void Awake ()
{
player = GameObject.FindGameObjectWithTag ("Player").transform;
//playerHealth = player.GetComponent <PlayerHealth> ();
//enemyHealth = GetComponent <EnemyHealth> ();
nav = GetComponent <UnityEngine.AI.NavMeshAgent> ();
}
void Update ()
{
//if(enemyHealth.currentHealth > 0 && playerHealth.currentHealth > 0)
//{
nav.SetDestination (player.position);
//}
//else
//{
// nav.enabled = false;
//}
}
}
现在Bunny可以一直追踪Player了