Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How to override scroll rect, but only for windows?

Discussion in 'UGUI & TextMesh Pro' started by sildeflask, Aug 22, 2023.

  1. sildeflask

    sildeflask

    Joined:
    Aug 16, 2023
    Posts:
    329
    I have a script to override scroll rect, but I want the methods I am overriding to work normally on mobile

    how can I achieve this?

    My current script is:

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using UnityEngine.EventSystems;
    4. using UnityEngine.UI;
    5. using System.Collections;
    6. public class PreventClickDrag : ScrollRect {
    7.     public override void OnBeginDrag(PointerEventData eventData) { }
    8.     public override void OnDrag(PointerEventData eventData) { }
    9.     public override void OnEndDrag(PointerEventData eventData) { }
    10. }
    11.  
    I was looking for something like:

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using UnityEngine.EventSystems;
    4. using UnityEngine.UI;
    5. using System.Collections;
    6.  
    7. public class PreventClickDrag : ScrollRect {
    8.  
    9.     public override void OnBeginDrag(PointerEventData eventData) {
    10. #if UNITY_ANDROID || UNITY_IOS
    11. //execute base method as normal
    12. #else
    13. return;
    14. }
    15.     public override void OnDrag(PointerEventData eventData) {
    16. #if UNITY_ANDROID || UNITY_IOS
    17. //execute base method as normal
    18. #else
    19. return;
    20. }
    21.     public override void OnEndDrag(PointerEventData eventData) {
    22. #if UNITY_ANDROID || UNITY_IOS
    23. //execute base method as normal
    24. #else
    25. return;
    26.  }
    27. }
    28.  
    Please advise me on the best way to go
    Thanks!