Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

How can I make scrollrect functions run from inheritance?

Discussion in 'Scripting' started by jose8779, Jul 28, 2022.

  1. jose8779

    jose8779

    Joined:
    Jun 15, 2020
    Posts:
    2
    I created a class that inherits the scrollrect, but does not execute any function of the scrollrect. The C# code is

    Code (CSharp):
    1.  public class scroll : ScrollRect
    2. {
    3.  
    4. public bool isEnable;
    5.  
    6. public override void OnBeginDrag(PointerEventData data)
    7. {
    8.  
    9.    var difference = data.pressPosition.x - data.position.x;
    10.    Debug.Log(difference);
    11.    if (difference is <= -1f or >= 1f)
    12.    {
    13.        isEnable = true;
    14.        this.enabled = false;
    15.        return;
    16.    }
    17.  
    18.    this.enabled = true;
    19.    base.OnBeginDrag(data);
    20.  
    21.  
    22. }
    23.  
    24. public override void OnDrag(PointerEventData eventData)
    25. {
    26.    base.OnDrag(eventData);
    27. }
    28.  
    29. public override void OnEndDrag(PointerEventData eventData)
    30. {
    31.  
    32.    isEnable = false;
    33.    if (!isEnable)
    34.        this.enabled = true;
    35.  
    36.    base.OnEndDrag(eventData);
    37. }
    How can I make scrollrect functions run from inheritance?

    that the scroll rect does not perform the vertical scroll function, when I execute the scroll it does not move anywhere.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,949
    The most obvious thing is in line 15 when you early out. Is that a meaningful way to change interaction with the basic ScrollRect or are you putting it into some kind of invalid state because you are only early-outing on the Begin??

    The source is all there for the original ScrollRect... attach the debugger and compare how it works with your overridden version. Most likely it is just early-out-ing at some point due to a property being different or a code path not being followed.
     
  3. jose8779

    jose8779

    Joined:
    Jun 15, 2020
    Posts:
    2
    Thanks I managed to solve it, for some strange reason it was giving me a conflict with another scrollrect but I managed to solve it