文章目錄
- 前言
- 一、連招系統的思路
- 二、連招系統示例(五連招)
- 1.Animator設定
- 2.撰寫腳本
前言
最近課程作業要求按照元神來做一個動作類游戲的小demo其中涉及到連招系統開發,網上找的很多教程都不太讓人滿意,經過我本人的各種查找與摸索,發現了如下的又簡單又快捷的方式,發布出來供大家參考
提示:以下是本篇文章正文內容,下面案例可供參考
一、連招系統的思路
連招系統的思路就是在給定時間間隔內玩家有沒有觸發攻擊,如果有則進入下一個動作,如果沒有則回傳到idle狀態,
二、連招系統示例(五連招)
1.Animator設定
在animator中設定trigger變數作為觸發動作狀態轉換的方法

animation1 animation2 animation3 animation4 分別代表不同影片之間轉換的trigger 同時設定一個reset代表回傳idle狀態
2.撰寫腳本
代碼如下(示例):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Combo : MonoBehaviour
{
//設定連招需要觸發的trigger的陣列
List<string> animlist = new List<string>(new string[] { "animation1", "animation2", "animation3", "animation4" });
public Animator animator;
public int combonum;//連招計數
public float reset;
public float resettime;//設定重置時間
// Update is called once per frame
void Update()
{
if(Input.GetMouseButtonDown(0)&& combonum < 4)
{
animator.SetTrigger(animlist[combonum]);
combonum++;
reset = 0f;
}
if(combonum>0)
{
reset += Time.deltaTime;
if(reset> resettime)//當超過時間間隔就回到初始狀態
{
animator.SetTrigger("Reset");
combonum = 0;
}
}
if(combonum==4)//當到達最后一個動作的時候重置
{
resettime = 2f;
combonum = 0;
}
else
{
resettime = 2f;
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/204677.html
標籤:其他
下一篇:掃雷c語言簡易版,它來了!!
