如何在运行时为补间动画更改endValueString?

vip*_*169 3 c# unity-game-engine dotween

我正在使用Unity商店中的DOTween pro资产以及textmeshpro.附件是显示我的设置的屏幕截图:

在此输入图像描述

我的场景中收藏品很少; 我希望每次收集项目时能够使用不同的文本运行动画.

以下是我的代码片段:

DOTweenAnimation[] animations = pickUpTexts.GetComponents<DOTweenAnimation>();
for(int i=0;i< animations.Length; i++)
{
    Debug.Log("animations " + animations[0].animationType);
    if (animations[i].animationType == DOTweenAnimationType.Text)
    {
        textAnimation = animations[i];
    }
    if (animations[i].animationType == DOTweenAnimationType.Move)
    {
        moveAnimation = animations[i];
    }
}
Run Code Online (Sandbox Code Playgroud)

以后收集项目时,我称之为:

textAnimation.endValueString = "New pick up collected, blah blah";
//textAnimation.DOPlay();
textAnimation.DORestart();
Run Code Online (Sandbox Code Playgroud)

基本上,我正在尝试更改endValueString动画并使用新值重新运行动画.收集拾取后,我可以endValueString在检查器中看到正在更新,但补间仍在播放(或不播放)相同的旧值.显示更新的屏幕截图如下所示: 在此输入图像描述

我尝试使用重新启动/播放更改,关闭组件的自动杀戮选项,尝试更改检查器中的循环计数器,尝试使用textAnimation.DORestart(true)但似乎没有任何工作.

到目前为止我找到的解决方案是不使用动画组件,因为它不可重复使用,只需在我的脚本中使用以下行:

pickUpTexts.GetComponent<TextMeshProUGUI>().DOText("New pick up collected, blah blah", 1f, true).SetRelative(true)
Run Code Online (Sandbox Code Playgroud)

Dem*_*ant 7

您无法更改DOTweenAnimation的endValue,但您可以使用ChangeEndValue更改它生成的补间的endValue :

// myDOTweenAnimation indicates a reference to the DOTweenAnimation component
myTween = myDOTweenAnimation.GetTweens()[0];
myTween.ChangeEndValue("something else");
Run Code Online (Sandbox Code Playgroud)

侧面注意:我是OP正在使用的工具的开发者.

  • [这个答案正在讨论中.](https://meta.stackoverflow.com/questions/371715/did-this-answer-require-the-op-to-disclose-affiliation) (2认同)