Author Topic: Can't Add function to with EventDelegate  (Read 4465 times)

Galahad_druid

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Can't Add function to with EventDelegate
« on: December 13, 2013, 11:18:54 AM »
Sadly when I try this:

  1.         void Start()
  2.         {
  3.                 EventDelegate.Add(GetComponent<UIPopupList>().onChange, this.OnControllerChange);
  4.         }
  5.  
  6.         private void OnControllerChange (string sel)
  7.         {
  8.                 switch (sel) {
  9.                 case "Default":
  10.                         print ("Normal Movement");
  11.                         GameManager.Player.Movement.controllerType = ThirdPersonMovement.ControllerType.Normal;
  12.                         break;
  13.                 case "Mouse":
  14.                         print ("Mouse Movement");
  15.                         GameManager.Player.Movement.controllerType = ThirdPersonMovement.ControllerType.MouseRotation;
  16.                         break;
  17.                 case "Click":
  18.                         print ("Click Movement");
  19.                         GameManager.Player.Movement.controllerType = ThirdPersonMovement.ControllerType.ClickToMove;
  20.                         GameManager.Player.Movement.Stop();
  21.                         break;
  22.                 }
  23.         }
  24.  

it triggers the following errors:
Quote
Assets/RPG 2.0/Scripts/Mobile/Player/ChangeMovementType.cs(8,31): error CS1502: The best overloaded method match for `EventDelegate.Add(System.Collections.Generic.List<EventDelegate>, EventDelegate)' has some invalid arguments

Assets/RPG 2.0/Scripts/Mobile/Player/ChangeMovementType.cs(8,31): error CS1503: Argument `#2' cannot convert `method group' expression to type `EventDelegate'

What I'm supposed to do? =[

UncleAcid

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 51
    • View Profile
Re: Can't Add function to with EventDelegate
« Reply #1 on: December 13, 2013, 11:43:24 AM »
EventDelegate callbacks can't have parameters. they also may need to be public (I don't recall if that is a condition only for using the inspector or not).

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Can't Add function to with EventDelegate
« Reply #2 on: December 13, 2013, 12:56:55 PM »
Doesn't need to be public if you're adding it from code.

The string parameter shouldn't be there, however. It's of "void FuncName (void)" type.