So i've created this script on for each draggable object in a ScrollView:
using UnityEngine;
using System.Collections;
public class Dragger : MonoBehaviour {
private bool dragged = false;
private EventDelegate evi;
private void Start()
{
evi
= new EventDelegate
(this,
"TurnOffDragged"); evi.oneShot = true;
}
private void OnDrag()
{
if(UICamera.currentTouch.pos.x > 300)
{
TweenButtonDelete();
}
if(UICamera.currentTouch.pos.x < 100)
{
TweenButtonBack();
}
}
private void OnClick()
{
if(dragged)
{
UICamera.currentTouch.clickNotification = UICamera.ClickNotification.None;
TweenButtonBack();
}
else
{
UICamera.currentTouch.clickNotification = UICamera.ClickNotification.Always;
Debug.Log ("Click!");
}
}
private void TweenButtonDelete()
{
TweenPosition
.Begin(gameObject, 0
.1f,
new Vector3
(85, transform
.localPosition.y, transform
.localPosition.z)); dragged = true;
}
private void TweenButtonBack()
{
TweenPosition
.Begin(gameObject, 0
.1f,
new Vector3
(0, transform
.localPosition.y, transform
.localPosition.z)).onFinished.Add(evi
); }
private void TurnOffDragged()
{
dragged = false;
}
}
So when dragging I tween to the correct position. Is it possible to set the position of the draggable object to the finger position just like on iOS? I've tried a few things but can't really figure it out.
EDIT:
Also these buttons are dynamically generated, see script below:
//Adds a new button to the list
private void AddNewButton()
{
GameObject clone = NGUITools.AddChild(Grid, ButtonPrefab);
UIEventListener.Get (clone).onClick += TweenPanel;
buttonCounter++;
clone.name = buttonCounter.ToString();
CurrentButton = clone;
SetAnchors(clone);
Grid.GetComponent<UIGrid>().Reposition();
}
So now the following problem arises, when the button is tweened the clicknotification should be none but TweenPanel is still called when clicking on the button. What should happen is, when the button is tweened to x = 85 the clicknotification of the button should be none. When the button is tweened back to x = 0 the clicknotification should be always. How can this be done?