使用EffectPlayer可以快速实现点击播放特效或在不同位置生成特效,减少代码中大量的Input监听代码。
可以自己写入EffectNames保存特效名称,使用时参照以下模板。
PS:1.使用前将EffectPlayer放入Plugins文件夹下,并添加引用
2.场景中必须添加主摄像机Tag标记为MainCamera
3.场景中必须添加UICanvas节点,用于2D3D点击转换。
4.本文资源链接EffectPlayer2.0
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using EffectPlayer;
public class TestScript : MonoBehaviour {
// Use this for initialization
void Start () {
EffectPlayerContainer.Add(EffectNames.jinbi_effect, EffectType.Effect_3DTo2D, 1, testCamera);
EffectPlayerContainer.Add(EffectNames.dianji_effect, EffectType.Effect_2D, 1);
EffectPlayerContainer.GetEffectPlayer(EffectNames.jinbi_effect, EffectType.Effect_3DTo2D).LeanMoveTo(startPos, targetPos, Vector2.Distance(startPos, targetPos) / 900f).setOnComplete(() => {
EffectPlayerContainer.GetEffectPlayer(EffectNames.dianji_effect,
EffectType.Effect_2D).Play(targetPos).SetOnComplete(RemoveThisPanel);
});
EffectPlayerContainer.Add(EffectNames.dianji_effect, EffectType.Effect_Input, 5);
}
// Update is called once per frame
void Update () {
EffectPlayerContainer.GetEffectPlayer(EffectNames.dianji_effect, Effect_Input).Input();
if (Input.GetMouseButtonDown(2)) {
EffectPlayerContainer.Destroy(EffectNames.dianji_effect);
}
}
}