i attach a image to the scrollrect gameobject, and attach event trigger to that image, i can not drag the image agin, i want a list that has 10 gun to choose, when i click the gun, i want to change the character’s gun, but when i drag the list, i just want to scroll the gun list. what should i do to the scrollrect ?
According to the documentation for EventTrigger:
Attaching this component to a GameObject will make that object intercept ALL events, and no event bubbling will occur from this object!
My approach has been to create a helper component that implements the OnSelect and OnDeselect handlers, like so:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class SelectableEventHelper : MonoBehaviour, ISelectHandler, IDeselectHandler {
Selectable selectable;
public string name;
void Start () {
selectable = gameObject.GetComponent<Selectable>();
}
public void OnSelect(BaseEventData data) {
Debug.Log("selected " + name);
}
public void OnDeselect(BaseEventData data) {
Debug.Log("deselected " + name);
}
}
With this helper class attached to each of the objects in my scrollview, I get notified of changes in selection but the events related to scrolling still bubble up appropriately.