Hollow - Knight Animation的串联

;unity动画机的Event事件

开头帧跟结尾帧加上脚本函数

Health的脚本(血条的脚本)

using JetBrains.Annotations;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Health : MonoBehaviour
{
    public Animator[] healthItems;
    public Animator geo;
    
    
    void Start()
    {
        
    }


    void Update()
    {
        
    }
    
    /// <summary>
    /// 受伤后的血条变化
    /// </summary>
    public void Hurt()
    {
        healthItems[0].SetTrigger("Hurt");
    }

    /// <summary>
    /// 开启协程 角色掉到地面的时候初始化血量和 物品栏
    /// </summary>
    /// <returns></returns>
    public IEnumerator ShowHealthItems()
    {
        for(int i = 0; i < healthItems.Length; i++)
        {
            healthItems[i].SetTrigger("ReCover");
            yield return new WaitForSeconds(0.2f);
            //Debug.Log(i);
        }
        geo.Play("Enter");
        yield return new WaitForSeconds(0.2f);
    }

    /// <summary>
    /// 隐藏血量和物品栏
    /// </summary>
    public void HideHealthItem()
    {
        geo.Play("Exit");
        for(int i = 0;i < healthItems.Length;i++)
        {
            healthItems[i].SetTrigger("Hide");
        }
    }
}

SoulOrb的脚步(角色栏)

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

public class SoulOrb : MonoBehaviour
{
    private Health health;
    private Animator animator;

    void Start()
    {
        health = FindObjectOfType<Health>();
        animator = GetComponent<Animator>();
    }

    /// <summary>
    /// 延迟显示Orb
    /// </summary>
    public void DelayShowOrb(float dalay)
    {
        StartCoroutine(ShowOrb(dalay));
    }
    /// <summary>
    /// 协程显示 Orb
    /// </summary>
    /// <param name="dalay"></param>
    /// <returns></returns>
    IEnumerator ShowOrb(float dalay)
    {
        yield return new WaitForSeconds(dalay);
        animator.SetTrigger("ReCover");
    }
    
    /// <summary>
    /// 隐藏Orb
    /// </summary>
    public void HideOrb()
    {
        animator.SetTrigger("Hide");
    }

    /// <summary>
    /// 调用Health的血条显示
    /// </summary>
    public void ShowHealthItems()
    {
        StartCoroutine(health.ShowHealthItems());
    }

    /// <summary>
    /// 调用Health的血条隐藏
    /// </summary>
    public void HideHealthItems() 
    {
        health.HideHealthItem();
    }

}

因为在Health脚本里面有动画机执行 Geo的方法 这时候就调用了三个动画机

主要是脚本的串联跟动画器的Event事件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值