You can attach IDragHandler interface within UnityEngine.EventSystems to detect drag event.
using UnityEngine;
using UnityEngine.EventSystems;
public class DragHandler : MonoBehaviour, IDragHandler
{
public void OnDrag(PointerEventData eventData)
{
//...
}
}
It gives you error probably because you are missing namespace UnityEngine.EventSystems or OnDrag function.
You can override ScrollRect component and replace it with existing one, but that’s a different approach.
//ScrollRectExtended.cs
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class ScrollRectExtended : ScrollRect
{
public override void OnDrag(PointerEventData eventData)
{
base.OnDrag(eventData);
//...
}
}
I would recommend you to use EventTrigger component. Just place it on same gameObject as ScrollRect and call your function from mainMenu. Once you understand how EventTrigger works (Redirecting to latest version of com.unity.ugui) you can switch to using interfaces instead.
Mmmm I think the EventTrigger sounds like a good solution But I need to learn how to use it from my script.
I’ve tried the other solution you gave me and the error was:
mainMenu' does not implement interface member UnityEngine.EventSystems.IDragHandler.OnDrag(UnityEngine.EventSystems.PointerEventData)’
Probably because I@m coming from Corona and Lua but this sounds like Chinese to me XD
My current script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.IO;
using DG.Tweening;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;
public class mainMenu : MonoBehaviour {
public ScrollRect scrollView;
void Start()
{
}
}
Where and how should I do the Trigger? or the onDrag? or both (just with learning purposes :)).
And… thanks a lot for your patience! Much appreciated!