Monday, September 19, 2022
HomeGame Developmentc# - How to learn Unity Ads initialization code construction?

c# – How to learn Unity Ads initialization code construction?

This code makes use of the C# ternary operator.

This assemble consists of three elements. A situation and two values.

<situation> ? <value_true> : <value_false>

When the situation is true, this assemble returns the primary worth. When the situation is fake, it returns the second worth.

So what occurs right here is that the situation Application.platform == RuntimePlatform.IPhonePlayer is being evaluated. When it’s true, then _gameId will get set to _iOSGameId. When it’s false, then _gameId will get set to _androidGameId.

If you’re feeling uncomfortable with ternary expression, then you may additionally write the entire methodology as this:

public void InitializeAds()
    if(Application.platform == RuntimePlatform.IPhonePlayer) 
        _gameId = _iOSGameId;
        _gameId = _androidGameId;

    Advertisement.Initialize(_gameId, _testMode, this); 

What’s instantly seen right here is that any platform besides iPhone is assumed to be Android. I’m not aware of the Unity ingame commercial API, however this has some apparent code scent to me.



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments