You've already forked taptap2024_GJ_chidouren
增加场景道具
This commit is contained in:
75
Assets/Scripts/Game/Component/SceneProp/GreenProp.cs
Normal file
75
Assets/Scripts/Game/Component/SceneProp/GreenProp.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
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<PlayerEntity> ();
|
||||
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<EnemyEntity> ();
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user