Reputation: 23
I'm having a problem in creating a yoyo scaling effect with DOTween. I have tried using DoScale, DOScaleShake and DOPunchScale. None seem to work. The rotation that I made works just fine, but I need it to scale as well and that is something I somehow cannot create.
Here is the current code
void Update()
{
DOTween.Sequence()
.Append(crownGlow.transform.DOLocalRotate(new Vector3(0, 0, 360), rotationSpeed, RotateMode.FastBeyond360).SetRelative())
.Append(crownGlow.transform.DOPunchScale(new Vector3(0.5f, 0.5f, 0.5f), scaleSpeed, 10, 1f));
}
I even tried it this way and it didn't work
DOTween.Sequence()
.Append(crownGlow.transform.DOScale(new Vector3(originalScale.x + 0.5f, originalScale.y + 0.5f, originalScale.z + 0.5f), scaleSpeed).SetEase(Ease.Linear))
.Append(crownGlow.transform.DOScale(originalScale, scaleSpeed).SetEase(Ease.Linear));
EDIT: With the help of Ryanas, I managed to figure out the solution
void Start()
{
originalScale = crownGlow.transform.localScale;
crownGlow.transform.DOLocalRotate(new Vector3(0, 0, 360), rotationSpeed, RotateMode.FastBeyond360).SetEase(Ease.Linear).SetLoops(-1, LoopType.Incremental).SetRelative();
var sequence = DOTween.Sequence()
.Append(crownGlow.transform.DOScale(new Vector3(originalScale.x + 0.5f, originalScale.y + 0.5f, originalScale.z + 0.5f), scaleSpeed))
.Append(crownGlow.transform.DOScale(originalScale, scaleSpeed));
sequence.SetLoops(-1, LoopType.Restart);
}
Upvotes: 2
Views: 19058
Reputation: 1827
What you're probably looking for is something like this. Sequences shouldn't be created in update every frame because then it means you're applying several sequences on this object every second.
Instead, you want to create the sequence in another function such as Awake or Start. You mentioned that you want it to Yoyo but you need to supply that when you set the number of loops it does. I recommend looking at the documentation for more information: http://dotween.demigiant.com/documentation.php
Here, I've set loop amount to be -1, which means it infinitely loops. You need to add .Join instead of .Append so the two tweens occur at the same time.
void Start()
{
var sequence = DOTween.Sequence()
.Append(crownGlow.DOLocalRotate(new Vector3(0, 0, 360), rotationSpeed, RotateMode.FastBeyond360).SetRelative())
.Join(crownGlow.DOPunchScale(new Vector3(0.5f, 0.5f, 0.5f), scaleSpeed, 10, 1f));
sequence.SetLoops(-1, LoopType.Yoyo);
}
Upvotes: 2