I’m having some trouble with my reward based advertising. My entire project’s in js but unfortunately there doesn’t seem to be much js support for this issue.
I’m using the following tutorial:
… and here’s my code
#pragma strict
import UnityEngine.Advertisements ;
function showAd () {
if (Advertisement.IsReady()) {
Advertisement.Show("", new ShowOptions(){resultCallback = HandleAdResult}) ;
}
}
function HandleAdResult(result : ShowResult) {
switch(result) {
case ShowResult.Finished :
Debug.Log ("Player Gets Reward") ;
break ;
case ShowResult.Skipped :
Debug.Log ("Player Skipped Ad") ;
break ;
case ShowResult.Failed :
Debug.Log ("Whoops! Ad didn't launch. Check connection, etc") ;
break ;
}
}
Unity only spits out a tonn of errors when i include “{resultCallback = HandleAdResult}”. Am I writing this incorrectly for js? How should i invoke my HandleAdResult function correctly?
Thanks in advance! Would be amazing if i could earn a few pennies for all my hard work.
There’s almost nobody left on the forums that are using UnityScript anymore, so getting help for stuff that’s not C# will be hard.
What’s happening here:
Advertisement.Show("", new ShowOptions(){resultCallback = HandleAdResult});
Is a shorthand form for this:
var showOptions = new ShowOptions();
showOptions.resultCallback = HandleAddResults;
Advertisement.Show("", showOptions);
That might work, but I can’t remember quite how UnityScript’s constructors work (is ‘new’ used?), and I’m not sure if UnityScript handles delegates.
(In case you don’t know, UnityScript is the community’s name for what Unity refers to as ‘JavaScript’, as the language is most definitely not JavaScript)
That’s a little concerning though. Coming from a web design background unity script syntax was a lot more approachable (even if it is only derivative from JavaScript ). Would be a shame if they were phasing it out.