Parameters do not match the delegate

I’m trying to implement google’s reward based video ad in my unity game but on " rewardAd.OnAdRewarded += HandleOnAdRewarded;" it shows 'parameter doesn’t match the delegate.
Also my complete code for that handler is this:
" public void HandleOnAdRewarded(Object sender, Reward args){

string type = args.Type;
double amount = args.Amount;
print("User rewarded with: " + amount.ToString() + " " + type);

rew.text = “rewarded!”;

} "

That means your delegate (OnAdRewarded) has a different signature than what you are trying to assign to it.

So, in your case, you are trying to assign a method that takes an object and a Reward.

OnAdRewarded may not take those two parameters. You just need to make sure you are assigning the right stuff to it.

1 Like

So what should my corrected code be?
It’s first time I’m using ads so I don’t know much about it

Is this where you got your information?

I have no idea why they included the sender parameter but simply remove it and it 'should’™ work. Even on that page they dont mention the sender parameter, they just have it in the code?

1 Like

Yeah that’s the page, not so beginner friendly, alright I’ll remove the parameter , thanks

In your code “Object” might be UnityEngine.Object. The delegate’s parameter’s type is “object”, which is an alias for “System.Object”.

Either one of these should work.

public void HandleOnAdRewarded(object sender, Reward args)

public void HandleOnAdRewarded(System.Object sender, Reward args)
1 Like

Yeah, there is a difference between Object and object. They use the lower case in that doc while you have uppercase. That might be the only thing wrong. I haven’t used google ads, so it’s a guess.

1 Like

A blunder I guess, thanks

Thanks for the code bruh!

Not necessarily. If you’re using the System namespace, “object” will be the same as “Object”. If you’re using the UnityEngine namespace, “Object” will be the same as UnityEngine.Object.

If you’re using both the System and UnityEngine namespaces, you will get an error when you try to use “Object”, because it doesn’t know whether you mean UnityEngine.Object or System.Object.

Yes, you will get an error. But seeing as how this isn’t what was said and I was simply trying to solve their issue, I wasn’t going to go into that much detail. Still possibly good info to add.