我正在使用 DOTween pro来自 Unity 商店的 Assets 以及 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];
}
}
稍后当元素被收集时,我称之为:
textAnimation.endValueString = "New pick up collected, blah blah";
//textAnimation.DOPlay();
textAnimation.DORestart();
基本上,我正在尝试更改动画的 endValueString
并使用新值重新运行动画。当收集拾取时,我可以看到 endValueString
在检查器中更新,但 Tween 仍在播放(或不播放)相同的旧值。显示更新的屏幕截图如下所示:
我尝试使用 Restart/Play 进行更改,关闭组件的自动终止选项,尝试更改检查器中的循环计数器,尝试使用 textAnimation.DORestart(true)
但似乎没有任何效果.
目前我找到的解决方案是不使用动画组件,因为它不可重复使用,只需在我的脚本中使用以下行:
pickUpTexts.GetComponent<TextMeshProUGUI>().DOText("New pick up collected, blah blah", 1f, true).SetRelative(true)
最佳答案
您不能更改 DOTweenAnimation 的 endValue,但可以使用 ChangeEndValue 更改它生成的补间的 endValue :
// myDOTweenAnimation indicates a reference to the DOTweenAnimation component
myTween = myDOTweenAnimation.GetTweens()[0];
myTween.ChangeEndValue("something else");
旁注:我是 OP 使用的工具的开发者。
关于c# - 如何在运行时更改补间动画的 endValueString?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51574914/