Hello people,
I’ve never really learnt c# but in order for ads to work in my game i need to impliment some c# so heres my “ads.cs” script, and i get the following errors:
Assets/MyEngine/Scenes/Menu Ads/ads.cs(6,14): error CS8025: Parsing error
Assets/MyEngine/Scenes/Menu Ads/ads.cs(6,14): error CS1027: Expected `#endif’ directive
And heres my code:
using UnityEngine;
using System.Collections;
public class ads : MonoBehaviour {
}
#if UNITY_IPHONE
private const string appId = "10021";
private const string secret =
"7654645645";
#elif UNITY_ANDROID
private const string appId = "10021";
private const string secret =
"7654645645";
#else
private const string appId = "10021";
private const string secret = "7654645645";
#endif
PlayAdsSDK.SDKReady += SDKReady;
PlayAdsSDK.InterstitialReady += InterstitialReady;
PlayAdsSDK.InterstitialShown += InterstitialShown;
PlayAdsSDK.InterstitialFailed += InterstitialFailed;
PlayAdsSDK.InterstitialClosed += InterstitialClosed;
PlayAdsSDK.SDKVersion += SDKVersion;
PlayAdsSDK.Initialize (appId, secret);
If anyone could help me, or maybe push me in the right direction that’d be great 
Fersuta
The curly bracket on line 7 should go behind everything.
Right now, you have most of your variables and function calls outside of the class ads. This is not allowed.
EDIT: Also, you can only run functions from inside another function, so I put those commands inside the Start() function.
using UnityEngine;
using System.Collections;
public class ads : MonoBehaviour {
#if UNITY_IPHONE
private const string appId = "1002161";
private const string secret =
"08f806f81ff3a4e628c60a26ab346670bface5025315e37205266181ce3b966f";
#elif UNITY_ANDROID
private const string appId = "1002161";
private const string secret =
"08f806f81ff3a4e628c60a26ab346670bface5025315e37205266181ce3b966f";
#else
private const string appId = "1002161";
private const string secret = "08f806f81ff3a4e628c60a26ab346670bface5025315e37205266181ce3b966f";
#endif
void Start() {
// These are commands that need to run. So I'm putting
// them in Start. You can only run commands from inside
// a function. The only exception is the Main() loop
// but Unity takes care of that.
PlayAdsSDK.SDKReady += SDKReady;
PlayAdsSDK.InterstitialReady += InterstitialReady;
PlayAdsSDK.InterstitialShown += InterstitialShown;
PlayAdsSDK.InterstitialFailed += InterstitialFailed;
PlayAdsSDK.InterstitialClosed += InterstitialClosed;
PlayAdsSDK.SDKVersion += SDKVersion;
PlayAdsSDK.Initialize (appId, secret);
}
// Here's the end of the class.
}
Thanks for the reply @Garth, i tried your fix, but now i have these following errors. C# is so confusing.
So you have this section of code. What it is doing is listening to “events”. So PlayAdsSDK will say “Hey! The SDK is ready!” and here you are saying, “When the SDK is ready, run my function HandleSDKReady()”.
The problem here is that PlayAdsSDK doesn’t know what you want HandleSDKReady to do, and I don’t know what HandleSDKReady is supposed to do.
EDIT: Changed SDKReady() to HandleSDKReady() so it’s not confused with PlayAdsSDK.SDKReady.
void Start() {
// The left of the "+=" is what event you are listening to.
// The right of the "+=" is what command you
// want to run when the event occurs.
PlayAdsSDK.SDKReady += HandleSDKReady;
}
void HandleSDKReady() { // This line may be different depending on PlayAds
// What is supposed to happen when the SDK is ready?
// I don't know!
Debug.Log("The SDK is ready!");
}
Still no luck 
But heres the short reference guide i was trying to follow, maybe it will show you what im trying to do 
Okay, it looks like maybe you can comment all those lines out. Everything with a += next to it. You should still run
PlayAdsSDK.Initialize (appId, secret);
There’s a huge downside to this though. Your app won’t know if it can display an interstitial ad. You won’t know if a ad displayed properly, or if the player has closed the ad yet, or if it failed to load, or if the app failed to contact PlayAds, etc… You will need a programmer to handle how to deal with all that.
using UnityEngine;
using System.Collections;
public class ads : MonoBehaviour {
#if UNITY_IPHONE
private const string appId = "1002161";
private const string secret =
"08f806f81ff3a4e628c60a26ab346670bface5025315e37205266181ce3b966f";
#elif UNITY_ANDROID
private const string appId = "1002161";
private const string secret =
"08f806f81ff3a4e628c60a26ab346670bface5025315e37205266181ce3b966f";
#else
private const string appId = "1002161";
private const string secret = "08f806f81ff3a4e628c60a26ab346670bface5025315e37205266181ce3b966f";
#endif
void Start() {
// PlayAdsSDK.SDKReady += SDKReady;
// PlayAdsSDK.InterstitialReady += InterstitialReady;
// PlayAdsSDK.InterstitialShown += InterstitialShown;
// PlayAdsSDK.InterstitialFailed += InterstitialFailed;
// PlayAdsSDK.InterstitialClosed += InterstitialClosed;
// PlayAdsSDK.SDKVersion += SDKVersion;
PlayAdsSDK.Initialize (appId, secret); // Still need this!
}
}
Woo! no more errors! Thanks for all your help Garth! Like seriously you’re a lifesaver!
And i think i can control all the ad settings from the control panel on the website 
Sweet! Glad I could help!
One note though, those lines we took out aren’t for configuration. They’re there so your game can fail “gracefully” if something goes wrong.
Eg: PlayAds will try to grab an ad from the internet for 10 seconds. If there’s no internet connection, then your app will just sit there for 10 seconds before the player can continue. If you get a programmer to put those lines of code back in, then you could just skip the 10 seconds of waiting for an ad that will never arrive.
Oh cool, thanks for pointing that out, i wouldn’t have realized and that could’ve been a disaster 
But thanks again!
Fersuta