最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - How do I change a Tweens end value that is inside a sequence? - Stack Overflow

programmeradmin1浏览0评论

I am trying to create a damage numbers system for my Unity project using DOTween and I have set up a nice looking sequence that I want to play whenever an enemy takes damage. The sequence involves a text object moving upwards and fading out. I have a pool of about 10 text objects to reuse, so when more than 10 numbers are needed at once the oldest one is reset and reused. My issue is that even though I am using SetRelative(true) the original end value is reused even though the text object has been moved. This means that the from the 11th instance onwards the number just appear in the same places they were the first time.

I want to avoid recreating a tween for every instance of damage because that would mean creating thousands of them, but I dont know how to reuse them with a new start and end value for the movement.

I saw this answer from Demigiant regarding changing values on tweens, but because this is a sequence I don't know how to get a reference to the Tweener itself. I cannot cast the sequence to a Tweener to gain access to ChangeEndValue.

Here is the code for my sequence:

_tweenSequence[i] = DOTween.Sequence()
                .Insert(0, display.DOFade(0, 1f))
                .Insert(0, display.transform.DOLocalMoveY(_canvasHeight/10f, 1f).SetRelative(true))
                .Pause()
                .SetAutoKill(false)
                .OnComplete(() => display.gameObject.SetActive(false));

Here is how I am starting the tweens when damage is dealt:

    private void AnimateText(int index, Vector3 damageLocation)
    {
        var display = _displayTexts[index];
        
        var viewportPosition = _cam.WorldToViewportPoint(damageLocation);
        
        var screenPoint = Vector3.Scale(viewportPosition, new Vector3(_canvasWidth, _canvasHeight, 1));
        
        // reset the text position
        display.transform.position = screenPoint;
        
        _tweenSequence[index].Restart();
    }

Thanks.

发布评论

评论列表(0)

  1. 暂无评论