2

The call backs aren't being fired, can't see what's wrong, I bought the $5 pack of samples and as far as I can tell I'm following their pattern properly. I've used this before successfully.

So in this class below a particular button has been either pressed or is being de-selected. In this case I'm specifically debugging the selected tween, but neither work properly. The InstantSelectionSpritesUp() function works fine, it manually reaches in and sets the colors alpha back up to 1. This works fine, so I've commented it out and am now trying the tween. The tween does not work. Via the Debug.Log I know that SetAsSelected() and FadeSelectionSpritesUp() are in fact being called. UpdateIconAlpha() and UpdateBGAlpha are not being called though, because there is no log printing to the console. StopTweens() is there because iTween doesn't automatically destroy pre-existing tweens when you call new ones on the same GameObject. I have commented this out and nothing changes, so that's not the issue. It's gotta be something wrong with how I've formatted the iTween call.

public class NavigationButton : MonoBehaviour{
// this is the super class for all of the navigation buttons

public UISprite bgDeselected;
public UISprite bgSelected;
public UISprite iconDeselected;
public UISprite iconSelected;

protected bool isCurrentlySelected = false;
protected float fadeTime = 0.5f;
protected Color alphaZero = new Color( 1.0f, 1.0f, 1.0f, 0.0f );
protected Color alphaOne = new Color( 1.0f, 1.0f, 1.0f, 1.0f );

// ----------------------------------------------------------------------------------------------------------------------------

void Start()
{
    // make the selected state of the button zero instantly so the user doesn't see it at all on app load
    InstantSelectionSpritesDown();
}

// ----------------------------------------------------------------------------------------------------------------------------

public void SetAsSelected()
{
    Debug.Log ( this.gameObject.name + ":SetAsSelected()" );

    // this funcion is called because this button has been pressed
    // we want this button to now show as being selected
    FadeSelectionSpritesUp();
    //InstantSelectionSpritesUp();

    isCurrentlySelected = true;
}

public void SetAsDeselected()
{
    Debug.Log ( this.gameObject.name + ":SetAsDeselected()" );

    // this funcion is called because the button another button in the nav has been pressed
    // we want this button to now show as being not selected
    //FadeSelectionSpritesDown();
    InstantSelectionSpritesDown();

    isCurrentlySelected = false;
}

// ----------------------------------------------------------------------------------------------------------------------------

protected void FadeSelectionSpritesDown()
{
    Debug.Log ( this.gameObject.name + ":FadeSelectionSpritesDown() :: iconSelected.gameObject:"+iconSelected.gameObject+" :: bgSelected.gameObject:"+bgSelected.gameObject  );
    //StopTweens();??

    // this function fades the alpha of the BG and Icon sprites down to 0% alpha
    iTween.ValueTo( iconSelected.gameObject ,iTween.Hash( "from", 1.0f, "to", 0.0f, "time", fadeTime, "onUpdate", "UpdateIconAlpha"));
    iTween.ValueTo( bgSelected.gameObject ,iTween.Hash( "from", 1.0f, "to", 0.0f, "time", fadeTime, "onUpdate", "UpdateBGAlpha"));
}

protected void FadeSelectionSpritesUp()
{
    Debug.Log ( this.gameObject.name + ":FadeSelectionSpritesUp() :: iconSelected.gameObject:"+iconSelected.gameObject+" :: bgSelected.gameObject:"+bgSelected.gameObject  );
    StopTweens();

    // this function fades the alpha of the BG and Icon sprites up to 100%
    iTween.ValueTo( iconSelected.gameObject ,iTween.Hash( "from", 0.0f, "to", 1.0f, "time", fadeTime, "onUpdate", "UpdateIconAlpha"));
    iTween.ValueTo( bgSelected.gameObject ,iTween.Hash( "from", 0.0f, "to", 1.0f, "time", fadeTime, "onUpdate", "UpdateBGAlpha"));
}

// ----------------------------------------------------------------------------------------------------------------------------

protected void StopTweens()
{
    // iTween doesn't destroy tweens that are already going if a new tween is added to the same object, so we need to destroy existing tweens manually
    iTween.Stop(iconSelected.gameObject);
    iTween.Stop(bgSelected.gameObject);
}

protected void UpdateIconAlpha( float alphaAsFloat )
{
    Debug.Log ( this.gameObject.name + ":UpdateIconAlpha() :: alphaAsFloat:"+alphaAsFloat+" :: bgSelected.gameObject:"+iconSelected  );
    iconSelected.color = new Color( alphaOne.r, alphaOne.g, alphaOne.b, alphaAsFloat );
}

protected void UpdateBGAlpha( float alphaAsFloat )
{
    Debug.Log ( this.gameObject.name + ":UpdateBGAlpha() :: alphaAsFloat:"+alphaAsFloat+" :: bgSelected.gameObject:"+bgSelected  );
    bgSelected.color = new Color( alphaOne.r, alphaOne.g, alphaOne.b, alphaAsFloat );
}

// ----------------------------------------------------------------------------------------------------------------------------

protected void InstantSelectionSpritesDown()
{
    // this function instantly sets the alpha of the BG and Icon sprites to 0% alpha
    iconSelected.color = alphaZero;
    bgSelected.color = alphaZero;
}

protected void InstantSelectionSpritesUp()
{
    // this function instantly sets the alpha of the BG and Icon sprites to 100% alpha
    iconSelected.color = alphaOne;
    bgSelected.color = alphaOne;
}}

Any thoughts?

Thanks! Dela

RebelFuture.com OpenSourceRebellion.com

Dela Torre
  • 51
  • 8
  • Could have something to do with compatibility with Unity 5. Did you see the warning on the iTween download? – kaybee99 Oct 28 '15 at 08:24

0 Answers0