unity实现 动作游戏的连招/连击
工程下载:https://files.cnblogs.com/files/sanyejun/ComboAttack.7z
全网也没查到比较好的资料,自己弄了个
一共是3个脚本
先上图
黑色为触发条件
绿色和红色为2个动画Behaviour脚本
注意:attack01 attack02 attack03 ——> idle 的has exit time 需要勾选上,其他的都不用
然后attack01 可以连到 attack02 , attack02 可以连到 attack03
那么attack01 和 attack02 需要在动画转折的地方添加动画事件
一个动作
【1.起手】--------------【2.攻击】--------------【3.准备收招转idle】---------------【4.转idle】
那么在 3 这个时间点,添加动画事件,如果可以连击,进入下一个攻击动作,没有的话则进入idle
添加事件:ComboCheck 参数:Int 如果需要2下进下个动作则填 2, 3下则填3
我们这里的attack01 填参数2 attack03填参数3
脚本:
挂人物身上的
using System.Collections;
using System.Collections.Generic;
using UnityEngine; public class ComboAttack : MonoBehaviour
{
public Animator anim;
public int clickNum = 0;
private float lastClickedTime = 0;
//2下连击之间按键的最长延迟
public float maxComboDelay = 0.9f;
private static readonly int AttackCombo = Animator.StringToHash("attackCombo"); // Start is called before the first frame update
void Start()
{
anim = GetComponent<Animator>();
} // Update is called once per frame
void Update()
{
if (Time.time - lastClickedTime > maxComboDelay)
{
clickNum = 0;
} if (Input.GetMouseButtonDown(0))
{
lastClickedTime = Time.time;
clickNum++;
if (clickNum == 1)
{
anim.SetBool(AttackCombo, true);
} clickNum = Mathf.Clamp(clickNum, 0, 3);
}
} public void ComboCheck(int num)
{
if (clickNum >= num)
{
anim.SetBool(AttackCombo, true);
}
} public void ClearComboClickNum()
{
clickNum = 0;
}
}
动画的Behaviour
using System.Collections;
using System.Collections.Generic;
using UnityEngine; public class AttackComboNumClear : StateMachineBehaviour
{
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
animator.GetComponent<ComboAttack>().ClearComboClickNum();
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine; public class AttackComboBehaviour : StateMachineBehaviour
{
private static readonly int Attack = Animator.StringToHash("attackCombo"); // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
animator.SetBool(Attack, false);
}
}
unity实现 动作游戏的连招/连击的更多相关文章
- 张瀚荣:如何用UE4制作3D动作游戏
转自:http://www.gamelook.com.cn/2015/06/218267 GameLook报道/ 6月5日,2015年第三期GameLook开放日‧虚幻引擎专场活动在上海正式举行,此次 ...
- 总结使用Unity 3D优化游戏运行性能的经验
原地址:http://www.gameres.com/msg_221889.html 作者:Amir Fasshihi 流畅的游戏玩法来自流畅的帧率,而我们即将推出的动作平台游戏<Shadow ...
- (转)总结使用Unity 3D优化游戏运行性能的经验
http://www.199it.com/archives/147913.html 流畅的游戏玩法来自流畅的帧率,而我们即将推出的动作平台游戏<Shadow Blade>已经将在标准iPh ...
- [转]总结使用Unity 3D优化游戏运行性能的经验
转载自:http://www.gameres.com/msg_221889.html 作者:Amir Fasshihi 流畅的游戏玩法来自流畅的帧率,而我们即将推出的动作平台游戏<Shadow ...
- Spine应用--使用Spine动画制作动作游戏
在前面的文章中,已经陆陆续续的讲解了一些使用Spine动画的细节,有了这些细节,我们已经满足了在unity中使用Spine动画制作动作游戏的技术基础. 那么,要使用Spine动画在unity中制作一款 ...
- Unity中制作游戏的快照游戏支持玩家拍快照
Unity中制作游戏的快照游戏支持玩家拍快照 有些游戏支持玩家“拍快照”,也就是将游戏的精彩瞬间以图片的形式记录下来的功能.这个功能比较有趣,而且以后的用途也会很广,为此本节打算介绍:截取矩形区域内游 ...
- Unity塔防游戏开发
Unity3D塔防开发流程 配置环境及场景搭建编程语言:C#,略懂些许设计模式,如果不了解设计模式,BUG More开发工具:Unity3D编辑器.Visual Studio编译器开发建议:了解Uni ...
- unity开发android游戏
环境搭建: Unity+JDK+Android Studio+Android SDK(+NDK) 教程:unity开发android游戏(一)搭建Unity安卓开发环境 注意“Build System ...
- Siki_Unity_1-8_使用Unity开发2D游戏_PongGame
Unity 1-8 使用Unity开发2D游戏 PongGame 任务1:演示 http://pan.baidu.com/s/1pKUHsev; up2i 任务2:案例介绍 创建PongGame,注意 ...
- unity开发android游戏(一)搭建Unity安卓开发环境
unity开发android游戏(一)搭建Unity安卓开发环境 分类: Unity2014-03-23 16:14 5626人阅读 评论(2) 收藏 举报 unity开发androidunity安卓 ...
随机推荐
- CSS 魔法与布局技巧
CSS 布局与视觉效果常用实践指南 在我一篇随笔中其实有说到十大布局,里面有提到 flex 布局.grid 布局.响应式布局,不过没有提到容器查询这个,现在说下这三个布局然后穿插下容器查询把. 1️⃣ ...
- 鸿蒙Next开发实战教程--银行App
昨天Mate70的官方预热直接引起网络爆炸,现在预约人数已经两百多万了,大家都这么有米吗 今天跟大家分享一个银行app实战教程. 页面虽然看起来比较复杂,但是仔细分析一下并不难,下面跟大家分享一下本项 ...
- 接口测试策略(一、概念&流程&范围)
接口测试概要 接口测试概念 什么是接口测试? 维基百科对接口测试的定义如下: API testing is a type of software testing that involves testi ...
- web ctf日记
X-Forworded-For:从本地访问 Refer:从**网址访问 一句话木马:`<?php @eval($_POST['a']);?>` eval将a作为PHP程序post进入(用蚁 ...
- 华为MAAS、阿里云PAI、亚马逊AWS SageMaker、微软Azure ML各大模型深度分析对比
一.技术架构深度对比 1. 硬件基础设施 平台 自研芯片 分布式训练方案 边缘协同能力 华为MAAS 昇腾Ascend 910 + Atlas 900集群 MindSpore + HCCL(华为集合通 ...
- harbor自建https证书生成
1.生成CA证书 # 生成 RSA 私有秘钥 openssl genrsa -out ca-key.pem 4096 # 生成CSR(Certificate Signing Request),CSR和 ...
- Step-by-step FTP to ABAP Proxy
引自:https://wiki.scn.sap.com/wiki/display/XI/Step-by-step+FTP+to+ABAP+Proxy ABAP Server Proxy Area: S ...
- 开源公开课丨大数据调度系统Taier任务调度介绍
一.直播介绍 前几期,我们为大家分享了Taier基本介绍.控制台.Web前端架构及数据开发介绍,本期我们为大家分享Taier任务调度介绍. 本次直播我们将从Taier的任务调度实例生成.调度及提交等方 ...
- 【公开课】芯片ATE测试—93K机台与Smartest软件介绍
当前,随着中国集成电路产业的高速发展,芯片测试作为确保产品良率与可靠性的关键环节,其技术人才缺口日益凸显.尤其在测试设备操作层面,行业普遍面临两大痛点: 一方面,高端ATE测试平台(如93K系统)操作 ...
- 9.Java SDK源码分析系列笔记-LinkedHashMap
目录 1. 是什么 2. 使用 3. 实现 3.1. uml 3.2. 构造方法 3.3. put 3.3.1. 创建LinkedHashMap增强的节点--Entry[既是Node数组的节点又是双向 ...