p=64 Foundation of Skill System ;类恶魔城Demo学习

p=64 Foundation of Skill System ;类恶魔城Demo学习

创建Skill.cs 以后这个作为所有技能的父类
暂时定义检测是否可用技能和使用技能两个方法

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Skill : MonoBehaviour
{
    [SerializeField] protected float cooldown;
    protected float cooldownTimer; //计时器

    // Update is called once per frame
    void Update()
    {
        cooldownTimer -= Time.deltaTime;
    }

    public virtual bool CanUseSkill()
    {
        if(cooldownTimer < 0)
        {
            cooldownTimer = cooldown;
            return true;
        }

        return false;
    }

    public virtual void UseSkill()
    {

    }
}

新建个DashSkill,
在SkillManager 创个dashSkill对象。然后去unity新建对象放入。

DashSkill:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DashSkill : Skill
{
    public override bool CanUseSkill()
    {
        return base.CanUseSkill();
    }

    public override void UseSkill()
    {
        base.UseSkill();
    }
}

SkillManager:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SkillManager : MonoBehaviour
{
    public static SkillManager instance;   //静态方法

    public DashSkill dashSkill { get; private set; }
    //技能,待续
    public void Awake()
    {
        if (instance != null && instance != this)
        {
            Destroy(this.gameObject);  // 销毁重复实例
        }
        else
        {
            instance = this;          // 设置唯一实例
        }
    }

    public void Start()
    {
        dashSkill = GetComponent<DashSkill>();
    }
}


最后player调整一下,去掉之前在里面设置的冲刺CD相关的两个变量

    public void CheckForDashInput() 
    {
        if (IsGroundDetect()) 
        {
            return;
        }
        if (Input.GetKeyDown(KeyCode.Mouse0 ) && SkillManager.instance.dashSkill.CanUseSkill())
        {

            dashDir = Input.GetAxisRaw("Horizontal");
            if(dashDir == 0)
            {
                dashDir = facingDir;
            }
            stateMachine.ChangeState(dashState);
        }
    }

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值