No overload for method `destroyAfterCBEvent' takes `0' arguments

476 Views Asked by At

Error: No overload for method destroyAfterCBEvent' takes0' arguments

What is the solution of above problem>???

Chartboost.CBManager.didFailToLoadInterstitialEvent += destroyAfterCBEvent();

void destroyAfterCBEvent (string location)
{
    Debug.LogError ("CB Event failed, noads button destroyed");
    Destroy (gameObject);
 }

These are the code which are used and generating the errors..

1

There are 1 best solutions below

7
On

You're calling destroyAfterCBEvent, when you actually want to use a method group conversion to create a delegate to subscribe to the event. You need to take the brackets off (which is what makes it a method call). You want:

Chartboost.CBManager.didFailToLoadInterstitialEvent += destroyAfterCBEvent;

That's equivalent to:

Chartboost.CBManager.didFailToLoadInterstitialEvent +=
    new Action<string>(destroyAfterCBEvent);

Or according to your comments:

Chartboost.CBManager.didFailToLoadInterstitialEvent +=
    new GUIClickEventReceiver(destroyAfterCBEvent);

(The latter surprises me, given the Chartboost documentation.)

As an aside, it would be a good idea to change your code to follow normal .NET naming conventions - events and methods should both be PascalCased. Events should usually have a delegate compatible with EventHandler, too. (I don't know anything about ChartBoost, so it's possible that some of these problems are nothing to do with you... but the method name is definitely something you can fix.)