This commit is contained in:
GL 2024-12-18 16:55:00 +08:00
parent f3cad5d509
commit 2b93b14699
3 changed files with 25 additions and 15 deletions

View File

@ -68,7 +68,8 @@ public class Attack : MonoBehaviour
{ {
direction = (targetRole.transform.position - BulletStartPos.position).normalized; direction = (targetRole.transform.position - BulletStartPos.position).normalized;
} }
animator.SetInteger("State", 1); //animator.SetInteger("State", 1);
animator.SetTrigger("Attack");
lastAttackTime = Time.time; // 更新上次攻击时间 lastAttackTime = Time.time; // 更新上次攻击时间
} }
@ -85,7 +86,7 @@ public class Attack : MonoBehaviour
if (animator != null) if (animator != null)
{ {
animator.SetInteger("State", 0); //animator.SetInteger("State", 0);
} }
else else
{ {

View File

@ -40,8 +40,10 @@ public class Role : Fun
private float maxHp; private float maxHp;
[Header(("死亡动画编号"))] public int dieIndex=-1; [Header(("死亡动画编号"))] public int dieIndex=-1;
[Header("hpÌî³ä")] public Image Hpfiil; [Header("hp填充直接扣")] public Image Hpfiil;
[Header("hp填充慢慢扣")] public Image HpfiilYello;
[Header("扣血填充")] public GameObject HpTextPrefab; [Header("扣血填充")] public GameObject HpTextPrefab;
[Header("自己的画布")]public Canvas _Canvas; [Header("自己的画布")]public Canvas _Canvas;
[Header("自己的图片")] public SpriteRenderer spriteRenderers; // 存储所有的SpriteRenderer组件 [Header("自己的图片")] public SpriteRenderer spriteRenderers; // 存储所有的SpriteRenderer组件
@ -53,26 +55,30 @@ public class Role : Fun
float temp = hp; float temp = hp;
hp = value; hp = value;
if (Hpfiil!=null) // 更新血条显示
if (Hpfiil != null)
{ {
Hpfiil.fillAmount = hp / maxHp; Hpfiil.fillAmount = hp / maxHp;
// 使用 DOTween 动画平滑过渡血条填充
DOTween.To(() => HpfiilYello.fillAmount, x => HpfiilYello.fillAmount = x, hp / maxHp, 0.8f) // 0.5f 为过渡时间
.SetEase(Ease.InOutQuad); // 使用缓动效果,使血条变化更加平滑
} }
if (HpTextPrefab != null&& hp<maxHp) // 更新血量文本效果
if (HpTextPrefab != null && hp < maxHp)
{ {
GameObject go = GameObject.Instantiate(HpTextPrefab, _Canvas.transform); GameObject go = GameObject.Instantiate(HpTextPrefab, _Canvas.transform);
go.GetComponent<Text>().text = (temp - hp).ToString(); // 显示伤害值
go.GetComponent<Text>().text= (temp - hp).ToString(); FlashRedEffect(); // 血量减少时的红色闪烁效果
FlashRedEffect(); StopDoTween(0.2f); // 停止任何进行中的 DoTween 动画0.2s为示例值
StopDoTween(0.2f);
} }
// 判断角色是否死亡
if (hp <= 0) if (hp <= 0)
{ {
die(); die(); // 执行死亡处理
} }
} }
} }
[Header("掉落")] public float gold = 10f; [Header("掉落")] public float gold = 10f;

View File

@ -13,13 +13,16 @@ public class waypoints
public class SimplePathfindingDoTween : Fun public class SimplePathfindingDoTween : Fun
{ {
public waypoints waypoints = new waypoints();// 预设的路径点 public waypoints waypoints = new waypoints();// 预设的路径点
public float moveSpeed = 1f; // 控制移动速度的参数(更高值表示更快的速度)
public float moveSpeed; // 控制移动速度的参数(更高值表示更快的速度)
private int currentWaypointIndex = 0; // 当前路径点的索引 private int currentWaypointIndex = 0; // 当前路径点的索引
Vector3 Vector3 = new Vector3(); Vector3 Vector3 = new Vector3();
[Header("旋转的动画")]public GameObject obj; [Header("旋转的动画")]public GameObject obj;
public void MoveToNextWaypoint(GameObject gameObject) public void MoveToNextWaypoint(GameObject gameObject,float moveSpeed)
{ {
if (currentWaypointIndex < waypoints._waypoints.Count) if (currentWaypointIndex < waypoints._waypoints.Count)
{ {