Set float value and callback???
« on: April 25, 2015, 12:44:24 PM »
Hi,

Being relatively new to the Unity scene, I am struggling with the following task:

1) I need to adjust a certain float value ("abb") over time with easing (presumably using DOTween)
2) When the tween is completed, I need to set up a new tween with slightly different (random) parameters by calling ResetTweenParameters().

I should say that the documentation gives no clear example on how to do this basic task. Nor I have any real knowledge on callbacks usage. I tried to do the following:

Code: [Select]
DOTween.To(()=> abb, x=> abb = x, Random.Range(0.5f,1.5f), Random.Range(0.2f,2f)).OnComplete(ResetTweenParameters());
but it doesn't work saying OnComplete isn't possible in this case. I'm clueless, please help.

*

Daniele

  • Dr. Admin, I presume
  • *****
  • 378
    • View Profile
    • Demigiant
Re: Set float value and callback???
« Reply #1 on: April 25, 2015, 01:18:05 PM »
Hi,

In Unity (as in almost all engines/languages) floats are a value type, not a reference type. That means that if you pass "abb" alone to a tween, you are passing the numeric value of "abb" and not a reference to it, thus it won't be tweenable. You should write this instead (assuming "abb" is a variable of a class instance that you stored as "myClass"):

Code: [Select]
DOTween.To(()=> myClass.abb, x=> myClass.abb = x, Random.Range(0.5f,1.5f), Random.Range(0.2f,2f)).OnComplete(ResetTweenParameters());