Author Topic: How do I seperate between select item and scrolling in Scroll Panel?  (Read 2457 times)

RiRin

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
I tried to use scroll panel (draggable panel version).
I add buttons as item in scroll view.
When I scroll the panel, the button was pressed.
I don't want the button to be activate when I scroll the panel.

I had read doc but still cannot find the right solution.
I tried on OnDrag and OnDragFinished command and put some flag to check is it dragging or not.
But it did not work.

Need Help.

AndyGFX

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 24
    • View Profile
    • AndyGFX
Re: How do I seperate between select item and scrolling in Scroll Panel?
« Reply #1 on: October 22, 2012, 09:34:14 AM »
Try this.

I have assigned this script on buttons in panel with UIDragPanelContents too. Every button in my panel then works as DRAG event for drag content, Click event on button and Hold event on button.

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class OnClick_and_OnHold: MonoBehaviour
  5. {
  6.        
  7.         public float time_press = 0;
  8.         public float time_release = 0;
  9.         private bool inUse = false;
  10.         private float delta_time;
  11.         public UILabel label;
  12.        
  13.         void OnPress(bool isPressed)
  14.         {
  15.                                
  16.                         if(isPressed)
  17.                         {                      
  18.                                 time_press = Time.realtimeSinceStartup;
  19.                                 inUse = true;
  20.                         }
  21.                         else
  22.                         {
  23.                                 time_release = Time.realtimeSinceStartup;
  24.                                
  25.                                
  26.                                 if ((time_release-time_press)<0.25f)
  27.                                 {
  28.                                         this.MyOnClick();
  29.                                 }      
  30.                                
  31.                                 inUse = false; 
  32.                         }
  33.         }
  34.        
  35.         void OnDrag()
  36.         {
  37.                 this.inUse = false;    
  38.         }
  39.        
  40.         void MyOnClick()
  41.         {
  42.                 // YOUR CODE for CLICK HERE
  43.                
  44.         }
  45.        
  46.  
  47.         void MyOnHold()
  48.         {
  49.                 // YOUR CODE for HOLD here
  50.                
  51.         }
  52.  
  53.         void Update()
  54.         {
  55.                
  56.                 if (inUse)
  57.                 {
  58.                        
  59.                        
  60.                         delta_time = Time.realtimeSinceStartup - time_press;
  61.                         if (delta_time>0.5f)
  62.                         {                              
  63.                                 if (Input.touchCount < 2)
  64.                                 {
  65.                                         this.MyOnHold();
  66.                                        
  67.                                 }
  68.                         }
  69.                
  70.                 }
  71.         }
  72.        
  73. }
  74.  
  75.  
« Last Edit: October 22, 2012, 09:38:16 AM by AndyGFX »

pandey611

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: How do I seperate between select item and scrolling in Scroll Panel?
« Reply #2 on: April 29, 2014, 01:13:13 AM »
I need help in the above script.above script is making what i exactly want.
I want to drag uibuttons in scroll example of NGUi.

Regards,
Pradeep Pandey