c# - 如何在运行时更改补间动画的 endValueString?

标签 c# unity3d dotween

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

enter image description here

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

下面是我的代码片段:

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 仍在播放(或不播放)相同的旧值。显示更新的屏幕截图如下所示: enter image description here

我尝试使用 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/

相关文章:

c# - 连接铰链接头时将物体平稳地移动到位

c# - 将 .NET 4 线程转换为 .NET 2

c# - 按名称、标签或图层查找不活动的游戏对象

c# - C# 中的内联函数 block

c# - 从 MySqlCommand 获取生成的 SQL 语句

c# - 如何在 WPF 中找到 UserControl 宽度?

c# - 使用 LINQ to SQL 的 .NET 架构的最佳设计实践(需要 DAL?我们真的可以使用 POCO 吗?要采用的设计模式?)

c# - 更改windows默认播放设备