Passing constructor parameters in UnityScript


I’m trying to implement Unity Ads (C#) in a game i’ve written in UnityScript.
I can display “regular” ads with no problem, but i’ve come across a problem implementing rewarded ads.

The C# sample code for invoking a rewarded ad is as follows:

var options = new ShowOptions { resultCallback = HandleShowResult };  Advertisement.Show("rewardedVideo", options);

Where “HandleShowResult” is a callback function for when the ad is completed or skipped.

However, this code doesn’t work in UnityScript. I’ve searched for how this can be completed in UnityScript, but to no avail. Putting this code in the standard assets folder is not an option either, since the callback will need to talk to the rest of the game code which is written in UnityScript…

Grateful for any help!


What you see after the constructor aren’t parameters of the constructor. It’s an object initializer block. It’s just syntactical sugar for:

// C# / UnityScript
var options = new ShowOptions();
options.resultCallback = HandleShowResult;
Advertisement.Show("rewardedVideo", options);

So the UnityScript equivalent would actually look the same