Demigiant / dotween

A Unity C# animation engine. HOTween v2
http://dotween.demigiant.com
Other
2.33k stars 348 forks source link

ChangeValues on Dotween.To #304

Open 0kk470 opened 5 years ago

0kk470 commented 5 years ago

Hi there, I have Implemented a Number-Rolling Tweener for player's score increasing and I want to reuse it with different values every time the score is up. I use ChangeValues , But it seems not to work. self.twn = DOTween.To( function(iCurValue) numberText.text = math.floor(iCurValue) end, fBeginValue, fEndValue, fDuration) self.twn:ChangeValues(...) I read the documentation and found a note told that this works on regular tweens, not on ones that do more than just animate one value from one point to another. Is there any other ways to change the tweener's values and reuse it?

Demigiant commented 5 years ago

Ahoy!

That should actually work with string tweens. Is it possible that you didn't set your tween to avoid auto-kill-on-completion (by chaining a SetAutokill(false)), and thus it's killed and becomes un-reusable?

0kk470 commented 5 years ago

Ahoy!

That should actually work with string tweens. Is it possible that you didn't set your tween to avoid auto-kill-on-completion (by chaining a SetAutokill(false)), and thus it's killed and becomes un-reusable?

thx for replying. The autoKill is also set to 'false'. Actually,the tween can be reused but its endvalue will never change when restarted. Here's my code

    if self.twn then
        self.twn:ChangeValues(fBeginValue, fEndValue)
        self.twn:Restart()
    else
        self.twn = CS.DG.Tweening.DOTween.To(function(iCurValue) numberText.text = math.floor(iCurValue) end,fBeginValue,fEndValue,fDuration)
        self.twn:SetAutoKill(false)
    end
Demigiant commented 5 years ago

Oh, wait, I thought your previous code was a stub, but I see it's really like that... what coding language are you using? :B

0kk470 commented 5 years ago

Oh, wait, I thought your previous code was a stub, but I see it's really like that... what coding language are you using? :B

well, it's Lua. I used a solution called xlua so that I can call C# function in Lua VM

WispBart commented 3 years ago

I have the same problem when trying to change values on a running DOTween.To(). I haven't quite been able to isolate when it does or doesn't work. As you can see in the example I have a version that doesn't work and one that does. Unfortunately this doesn't solve the problem for my actual usecase.

using System.Collections;
using DG.Tweening;
using UnityEngine;

public class TweenTest : MonoBehaviour
{

    public float TweenMe;
    public float IncreaseValue = 10f;
    public float Duration = 1.5f;
    public float PerSeconds = 1f;

    private Tweener _tween;
    IEnumerator Start()
    {
        // Works, keeps tweening higher and higher smoothly:
        // _tween = DOTween.To(() => TweenMe, v => TweenMe = v, IncreaseValue, Duration).SetAutoKill(false);
        // Doesn't work, jumps from value to value instantly:
        _tween = DOTween.To(() => TweenMe, v => TweenMe = v, 0f, 0f).SetAutoKill(false);
        while (true)
        {
            yield return new WaitForSeconds(PerSeconds);
            _tween.ChangeValues(TweenMe, TweenMe + IncreaseValue, Duration);
        }
    }

}