Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Trying to understand how iTween.FadeTo works

Discussion in 'Scripting' started by chelder, May 29, 2016.

  1. chelder

    chelder

    Joined:
    Apr 21, 2015
    Posts:
    14
    The following code is NOT working:

    Code (CSharp):
    1. ExecuteMe(){
    2. ChangeGameObjectTextMeshAlphaColor(0f);
    3. iTween.FadeTo(gameObject, iTween.Hash ("alpha", 1f, "time", 2f,
    4. "oncomplete", "ReturnToOriginalAlphaTransparencyTweenOnComplete", "oncompletetarget", gameObject));
    5. }
    However, the following code is working:

    Code (CSharp):
    1. ExecuteMe(){
    2. ChangeGameObjectTextMeshAlphaColor(1f);
    3. iTween.FadeFrom(gameObject, iTween.Hash ("alpha", 0f, "time", 0.2f,
    4. "oncomplete", "ReturnToOriginalAlphaTransparencyTweenOnComplete", "oncompletetarget", gameObject));
    Unfortunately when the above code is executed a second time (or third, forth...), it does not work anymore. I mean, the game object keep being transparent.

    The text I'm fading from transparent to opaque is a Text Mesh. The rest of the functions are next:

    Code (CSharp):
    1. private void ReturnToOriginalAlphaTransparencyTweenOnComplete () {
    2. //iTween.MoveTo(gameObject,iTween.Hash("position",startingPosition,"time",0.5f,"delay",3f));
    3. iTween.FadeTo(gameObject, iTween.Hash ("alpha", 0f, "time", 2f, "delay", 1f));
    4.  
    5. }
    6.  
    7. ///<summary>
    8. /// Changes the alpha color of the text mesh of this game object.
    9. ///</summary>
    10. ///<returns>The game object text mesh alpha color.</returns>
    11. ///<paramname="alphaColor">0 would set the color to transparent. 1 without any transparency</param>
    12. private void ChangeGameObjectTextMeshAlphaColor (float alphaColor){
    13. Color scoreMultiplierColorInSceneView = GetComponent<TextMesh> ().color;
    14. scoreMultiplierColorInSceneView.a = alphaColor;
    15. GetComponent<TextMesh> ().color = scoreMultiplierColorInSceneView;
    16. }
    Why is happening that weird behaviour?
     
  2. chelder

    chelder

    Joined:
    Apr 21, 2015
    Posts:
    14
    I believe the solution to the second issue could be related to the following function:

    • Stop(GameObject target, bool includechildren) Stop and destroy all iTweens on a GameObject including its children.