将之前制作好的角色模型变成预制体,并命名为Player。
并将player的Tag设置为player.添加Rigidbody,Character Controller,Capsule Collider组件
将Rigidbody组件设置为运动学
这个角色是由RobotPlayer所控制。并且RobotPlayer是继承自BaseRobot。
其中BaseRobot代码如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BaseRobot : MonoBehaviour
{
public int hp = 100;//生命值血量默认是100
/// <summary>
/// 判断是否存活的函数
/// </summary>
/// <returns>血量</returns>
public bool IsAlive()
{
return hp > 0;
}
/// <summary>
/// 受到伤害的响应函数
/// </summary>
/// <param name="dmg"></param>
public void GetDamage(int dmg)
{
hp -= dmg;
if (!IsAlive())//如果死亡,调用死亡函数
{
Die();
}
}
public virtual void Die()
{
Destroy(this.gameObject);
}