冰块随机,减速

This commit is contained in:
GL 2024-12-24 14:10:25 +08:00
parent 4e4e313bb2
commit ab21a3f4a4
2 changed files with 20 additions and 16 deletions

View File

@ -85,7 +85,7 @@ public class Bullet : MonoBehaviour
[Header("子弹动画")] public Animator animator; [Header("子弹动画")] public Animator animator;
[Header("子弹移动参数")] public bool IsMove=true; [Header("子弹移动参数")] public bool IsMove=true;
[Header("子弹碰撞体")] public Collider2D Collider2D; [Header("子弹碰撞体")] public Collider2D Collider2D;
[Header("×Óµ¯ÌØЧԤÖÆÌå")] public GameObject effectPre; [Header("×Óµ¯ÌØЧԤÖÆÌå")] public List<GameObject> effectPres=new List<GameObject>();
private float timer = 0; private float timer = 0;
private void Update() private void Update()
{ {
@ -159,20 +159,23 @@ public class Bullet : MonoBehaviour
if (bulletAttributes==BulletAttributes.Fire) if (bulletAttributes==BulletAttributes.Fire)
{ {
if (effectPre!=null)
{ if (effectPres.Count==1)
GameObject go = Instantiate(effectPre, collision.transform); {
GameObject go = Instantiate(effectPres[0], collision.transform);
go.transform.position = new Vector2(collision.transform.position.x, collision.transform.position.y + 0.2f); go.transform.position = new Vector2(collision.transform.position.x, collision.transform.position.y + 0.2f);
go.GetComponent<Huo>().bullet = this; go.GetComponent<Huo>().bullet = this;
Debug.Log("创建火焰"); Debug.Log("创建火焰");
}
} }
} }
if (bulletAttributes == BulletAttributes.Water) if (bulletAttributes == BulletAttributes.Water)
{ {
if (effectPre != null) if (effectPres.Count > 1)
{ {
GameObject go = Instantiate(effectPre, collision.transform); GameObject go = Instantiate(effectPres[Random.Range(0,effectPres.Count-1)], collision.transform);
go.transform.position = new Vector2(collision.transform.position.x, collision.transform.position.y-0.2f); go.transform.position = new Vector2(collision.transform.position.x, collision.transform.position.y-0.2f);
collision.transform.GetComponent<enemy>().SlowDown(0.2f, 3f); collision.transform.GetComponent<enemy>().SlowDown(0.2f, 3f);
@ -182,7 +185,7 @@ public class Bullet : MonoBehaviour
} }
} }
}
} }
private float lastDamageTime = 0f; private float lastDamageTime = 0f;
private void OnTriggerStay2D(Collider2D collision) private void OnTriggerStay2D(Collider2D collision)

View File

@ -55,7 +55,7 @@ public class SimplePathfindingDoTween : Fun
.OnUpdate(() => { .OnUpdate(() => {
pathTween.timeScale = speedFactor; //pathTween.timeScale = speedFactor;
RotateTowardsTarget(); } RotateTowardsTarget(); }
@ -78,14 +78,15 @@ public class SimplePathfindingDoTween : Fun
// 控制DoTween的速度接受一个新的速度因子和一个恢复时间 // 控制DoTween的速度接受一个新的速度因子和一个恢复时间
public void ChangeSpeed(float newSpeedFactor, float restoreTime) public void ChangeSpeed(float newSpeedFactor, float restoreTime)
{ {
// 改变路径动画的速度因子 // 当前的时间缩放因子
pathTween.timeScale = newSpeedFactor; float currentSpeedFactor = pathTween.timeScale;
// 设置一个延迟恢复原始速度的功能 // 使用Tween来平滑地调整速度因子
DOTween.To(() => 0f, x => { }, 0f, restoreTime).OnKill(() => DOTween.To(() => currentSpeedFactor, x => pathTween.timeScale = x, newSpeedFactor, restoreTime)
{ .OnKill(() =>
Debug.Log("设置减速+++++++++++++++++"); {
// 在延迟结束后恢复原来的速度 Debug.Log("设置减速+++++++++++++++++");
// 在延迟结束后恢复原速度
pathTween.timeScale = 1f; // 恢复原速度 pathTween.timeScale = 1f; // 恢复原速度
}); });
} }