Hi,
Ok I try to make this draglaunch for the ball when the challenge pop and so I make some research on how work event trigger. After that I find that we can get the EventData in our functions as parameters …
And so I compute my code, and it seems that it works … but maybe too complicated and/or totally inapropriate.
Can I have your opinion on this please :
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
[RequireComponent (typeof (Ball))]
public class DragLaunch : MonoBehaviour {
private Ball ball;
private Vector3 dragStartPosition, dragEndPosition;
// Use this for initialization
void Start () {
ball = GetComponent<Ball> ();
}
public void DragStart (BaseEventData data) {
PointerEventData pointerData = data as PointerEventData;
dragStartPosition = pointerData.position;
}
public void DragEnd (BaseEventData data) {
PointerEventData pointerData = data as PointerEventData;
dragEndPosition = pointerData.position;
float dragSpeed = pointerData.clickTime;
Vector3 DragVelocity = new Vector3 (dragEndPosition.x - dragStartPosition.x, 0, (dragEndPosition.y - dragStartPosition.y) * dragSpeed);//dragEndPosition.x - dragStartPosition.x);
ball.Launch (DragVelocity);
}
}
edit: Ok after some more test, it seems that the clickTime value doesn’t work as expected or I’ve made some mistake, I’ve switch back to course code. But if there is any tips on eventdata I’ll take them 