Question by
andrewwebber25 · Dec 04, 2017 at 09:05 PM ·
c#error messagecompiler errorunityadsstring formatting
Error with String in code
Hey guys Im trying to make a Reward Ad Button in my game. Unity documentation tells me to copy this code into an empty script and attach it to a game object. This is the only error I get: Expected class, delegate, enum, interface, or struct. It points to the "private string gameID = "1486550";" part of my code at the top. (I have it commented in the code so you can find it). This app is being made for android so I didnt think that was the one that would give me issue. Any help is greatly appreciated!
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Advertisements;
//---------- ONLY NECESSARY FOR ASSET PACKAGE INTEGRATION: ----------//
#if UNITY_IOS
private string gameId = "1486551";
#elif UNITY_ANDROID
private string gameId = "1486550"; //THE STRING HERE IS THE ERROR
#endif
//-------------------------------------------------------------------//
[RequireComponent(typeof(Button))]
public class UnityAdsButton : MonoBehaviour
{
Button m_Button;
public string placementId = "rewardedVideo";
void Start ()
{
m_Button = GetComponent<Button>();
if (m_Button) m_Button.onClick.AddListener(ShowAd);
//---------- ONLY NECESSARY FOR ASSET PACKAGE INTEGRATION: ----------//
if (Advertisement.isSupported) {
Advertisement.Initialize (gameId, true);
}
//-------------------------------------------------------------------//
}
void Update ()
{
if (m_Button) m_Button.interactable = Advertisement.IsReady(placementId);
}
void ShowAd ()
{
ShowOptions options = new ShowOptions();
options.resultCallback = HandleShowResult;
Advertisement.Show(placementId, options);
}
void HandleShowResult (ShowResult result)
{
if(result == ShowResult.Finished) {
Debug.Log("Video completed - Offer a reward to the player");
}else if(result == ShowResult.Skipped) {
Debug.LogWarning("Video was skipped - Do NOT reward the player");
}else if(result == ShowResult.Failed) {
Debug.LogError("Video failed to show");
}
}
}
Comment
Answer by ShadyProductions · Dec 04, 2017 at 09:20 PM
Put that part inside the class not outside of it.