Unity制作王者荣耀笔记(三)人物播放攻击特效

把粒子拖到人物对象上,作为他的子物体

编写播放特效脚本挂在Player上

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

public class PlayerAttack : MonoBehaviour {
    Animator ani;
    [SerializeField]
    private ParticleSystem fire1;
    [SerializeField]
    private ParticleSystem fire2;
    // Use this for initialization
    void Start () {
        ani = GetComponent<Animator>();
	}

    public void Atk1()
    {
        ani.SetInteger("state",AnimState.ATTACK1);
    }
    public void Atk2()
    {
        ani.SetInteger("state", AnimState.ATTACK2);

    }
    public void Dance()
    {
        //用dance代替第三次攻击
        ani.SetInteger("state", AnimState.DANCE);

    }
    //动画监听事件,攻击动画播放完播放攻击特效
    public void EffectPlayer1()
    {
        fire1.Play();
    }
    public void EffectPlayer2()
    {
        fire2.Play();
    }
    //攻击动画播放完转换成Idle状态
    public void ResetIdle()
    {
        ani.SetInteger("state", AnimState.IDLE);
    }
}

创建UI界面模拟攻击:

拖拽对应的事件

发布了122 篇原创文章 · 获赞 13 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/qq_40229737/article/details/103578171