Author Topic: UIslider EventDelegate.Add Error..  (Read 2569 times)

pankus61

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 2
    • View Profile
UIslider EventDelegate.Add Error..
« on: March 16, 2014, 09:26:09 PM »
Hello i want make UISlider volume changing but two error;
My script;

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class VolumeOption : MonoBehaviour {
  5.        
  6.  
  7.         void Start ()
  8.         {
  9.                 UISlider _Volumeslider = GetComponent<UISlider>();
  10.                 _Volumeslider.sliderValue = AudioListener.volume;
  11.                 EventDelegate.Add(_Volumeslider.onChange,OnToggleChange);
  12.  
  13.         }
  14.        
  15.         void OnToggleChange (float val)
  16.         {
  17.                 AudioListener.volume = val;
  18.         }
  19. }

ERRORS;

  1. Assets/ScriptOther/VolumeOption.cs(11,31): error CS1502: The best overloaded method match for `EventDelegate.Add(System.Collections.Generic.List<EventDelegate>, EventDelegate)' has some invalid arguments

  1. Assets/ScriptOther/VolumeOption.cs(11,31): error CS1503: Argument `#2' cannot convert `method group' expression to type `EventDelegate'

How to fix? Thanks in advance. :)

(Sorry for bad english.)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIslider EventDelegate.Add Error..
« Reply #1 on: March 17, 2014, 01:38:03 AM »
Remove "float val".

The callback doesn't have any parameters. Change it to:
  1. void OnTogleChange () { AudioListener.volume = UISlider.current.value; }