2.写好Unity 每个Buff系统类的每一种Buff效果基础类;
using UnityEngine;using System.Collections;using System;public class BaseBuff : MonoBehaviour ,iperiod{ public float lifeTime; public float lastTime; public bool isDestroy = false; PRotected bool isBegin; public virtual void Begin(string[] _str) { isBegin = true; lastTime = lifeTime; } public virtual void Exit() { isBegin = false; lifeTime = lastTime; if (isDestroy) DestroyImmediate(this); } protected virtual void Update() { if(isBegin) lifeTime -= Time.deltaTime; if(lifeTime < 0) { Exit(); } }}public interface IPeriod{ void Begin(string[] _str); void Exit();}3.然后举例写一个buff类型例子
using UnityEngine;using System.Collections;using Police.PaoKu;public class SubDefend : BaseBuff{ public override void Begin(string[] _str) { base.Begin(_str); ParkourPlayerController.Instance.Player.gameObject.AddComponent<Defend>(); } public override void Exit() { base.Exit(); Destroy(ParkourPlayerController.Instance.Player.GetComponent<Defend>()); }}4.每个buff类型给予空物体,然后赋值给(1)的配置表
5.这样的优势是容易扩展,可以理解成工厂模式,而且改变每个buff代码互不影响。
新闻热点
疑难解答