Hey there,
so I spent the last hours trying to get to know the scripting side of NGUI (working with the latest version), especially the new way handling Events. I looked up the Upgrade-Tutorials and used the Searchfunction and got things to work.
Now I have a little problem. I don't know if it's my own stupidity or maybe a bug, so please enlighten me

I want to achieve this:
I have a Button at the Bottom of the Screen and a Sprite which is positioned by default offscreen at the top of the screen.
When the Button is hit the first time, the Sprite should come down (using TweenPosition) and stay at the middle of the screen.
Then, when the Button is hit again that certain sprites goes back to its initial position offscreen.
This is what I'm doing right now:
using UnityEngine;
using System.Collections;
public class BookButton : MonoBehaviour
{
public bool firstTap;
private GameObject gameBook;
private UIButton btn;
// Use this for initialization
void Start ()
{
firstTap = false;
gameBook = GameObject.FindGameObjectWithTag ("GAMEBOOK");
btn = GetComponent<UIButton> ();
}
public void BookClick ()
{
if(firstTap)
{
TweenPosition tp
= TweenPosition
.Begin(gameBook, 1
.0f,
new Vector3
(gameBook
.transform.localPosition.x,
350.0f,
gameBook.transform.localPosition.z));
EventDelegate.Add(tp.onFinished, Fin1);
}
else
{
TweenPosition tp2
= TweenPosition
.Begin(gameBook, 1
.0f,
new Vector3
(gameBook
.transform.localPosition.x,
-350.0f,
gameBook.transform.localPosition.z));
EventDelegate.Add(tp2.onFinished, Fin2);
}
}
void Fin1()
{
firstTap = false;
Debug.Log("FIN1");
}
void Fin2()
{
firstTap = true;
Debug.Log("FIN2");
}
}
When I hit PLAY in Unity and start clicking the Button the first time the Sprite comes down, when I hit it again it goes back up, hitting it again it comes back down. Hitting it again, nothing happens. It doesn't move back up.
What is interesting though is the change of my firstTap-bool:
First Time hitting the Button: sprites comes down -> true
Second Time hitting the Button: sprites comes down -> false
Third Time hitting the Button: sprites comes down -> false
Another more interesting thing is:
When I hit the Button the first time, Debug.Log prints "FIN2", which is right, but when I hit it again in order to move the sprite back Debug.Log prints "FIN1" but also "FIN2" again! That shouldn't be the case, because TweenPosition tp is played and finished, why is the EventDelegate sending both Events? Did I miss something?