Author Topic: how to Play sound automatically when item is centered in scroll view  (Read 2944 times)

sangramdange

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
hi all
i am pretty new to NGUI.
i could play sound on mouse press, mouse release and so on but how to Play sound automatically when item is centered in scroll view
regards
sangram

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: how to Play sound automatically when item is centered in scroll view
« Reply #1 on: April 15, 2014, 09:18:27 AM »
UICenterOnChild has the onFinished delegate you can set. Set it to your custom function that will play a sound inside.

sangramdange

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: how to Play sound automatically when item is centered in scroll view
« Reply #2 on: April 15, 2014, 03:01:42 PM »
thanks Michael
but since am a newbie  can you just give me hint on how to access the onfinished delegate in UICentreOnChild script,  through a custom script.
I was checking the uibutton message script that makes it very simple to understand. its has public variables  like Target, function name, trigger.. all i do is make a gameobject attach a custom script to it and put that in the target and access the function name that is set in my custom script....Simple and works great
bu cant do the  same with UICentreOnChild script.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: how to Play sound automatically when item is centered in scroll view
« Reply #3 on: April 16, 2014, 10:18:49 AM »
  1. EventDelegate.Add(centerOnChild.onFinished, MyFunction);
Same as it is with tweens, pretty much. Here's the full code of how to do it with a tween, for reference:
  1. void OnClick()
  2. {
  3.     TweenPosition tp = TweenPostion.Begin(targetObject, duration, targetPos);
  4.     EventDelegate.Add(tp.onFinished, MyFunction);
  5. }
  6.  
  7. public void MyFunction ()
  8. {
  9.     Debug.Log("Tween finished");
  10. }