diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Actor/ActorHItem.cs b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Actor/ActorHItem.cs index 1ac6fb92..918c02ac 100644 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Actor/ActorHItem.cs +++ b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Actor/ActorHItem.cs @@ -104,6 +104,7 @@ namespace GameLogic if (oneNum == 0) { m_imgValue.fillAmount = 0.1f; + AlignCarWithFillAmount(); return; } @@ -114,6 +115,30 @@ namespace GameLogic percent = 1; } m_imgValue.fillAmount = percent; + AlignCarWithFillAmount(); + } + + private void AlignCarWithFillAmount() + { + if (m_imgValue == null || m_rectCar == null) + return; + + // 获取 m_imgValue 的 RectTransform + RectTransform imgRectTransform = m_imgValue.GetComponent(); + + if (imgRectTransform == null) + return; + + // 获取 m_imgValue 的宽度 + float imgWidth = imgRectTransform.rect.width; + + // 计算裁剪后的 X 坐标 + float targetX = imgWidth * m_imgValue.fillAmount; + + // 更新 m_rectCar 的位置 + Vector3 localPosition = m_rectCar.localPosition; + localPosition.x = targetX - (imgWidth / 2); // 调整为相对于中心点的位置 + m_rectCar.localPosition = localPosition; } } }