using Cysharp.Threading.Tasks; using UnityEngine; namespace Game.Component.SceneProp { public class GreenProp : BaseProp { [SerializeField] private ColliderTriggerAction _spawn; [SerializeField, Header ("持续时长")] private float _skillDuration; [SerializeField, Header ("速度buff 持续时间")] private float _buffDuration; [SerializeField, Header ("速度buff额外系数")] private float _buffSpeedOffset; protected override void OnTriggerEnter2D (Collider2D other) { if (other.gameObject.CompareTag ("Player")) { if (this.isReady) { var entity = other.gameObject.GetComponent (); this.OnTrigger (entity); } } } protected override async void OnTrigger (PlayerEntity entity) { this._spawn.gameObject.SetActive (true); await UniTask.Delay ( (int)(this._skillDuration * 1000)); this._spawn.gameObject.SetActive (false); if (HasOnce) { this.gameObject.SetActive (false); } else { RefreshInvalidTime (); } } protected override void OnReady () { this._spawn.gameObject.SetActive (false); } public void OnTriggerEnterAction (Collider2D other) { if (other.gameObject.CompareTag ("Enemy")) { var entity = other.gameObject.GetComponent (); OnSubEnemySpeed (entity , this._buffSpeedOffset , this._buffDuration); } } protected void OnSubEnemySpeed (EnemyEntity entity , float speedOffset , float duration) { entity.AddSpeedBuff (duration , speedOffset); } #if UNITY_EDITOR protected void OnDrawGizmos () { //减速球, 绿色标签 Gizmos.color = Color.green; Gizmos.DrawWireSphere (transform.position , 0.5f); UnityEditor.Handles.Label (transform.position, "减速球"); } #endif } }