-1

I added unity monetization package then I write this script:

using UnityEngine;
using UnityEngine.Advertisements;

public class ADSSSS : MonoBehaviour
{
    private void Start()
    {
        Advertisement.Initialize("my google play ID", false);
    }
}

then in unity such an error occurred

Can't add script behaviour CoroutineExecutor because it is an editor script. To attach a script it needs to be outside the 'Editor' folder. UnityEngine.Advertisements.Advertisement:.cctor () ADSSSS:Start () (at Assets/Scripts/ADSSSS.cs:8)

Can't add script behaviour ApplicationQuit because it is an editor script. To attach a script it >needs to be outside the 'Editor' folder. UnityEngine.Advertisements.Advertisement:.cctor () ADSSSS:Start () (at Assets/Scripts/ADSSSS.cs:8)

Initializing Unity Ads. UnityEngine.Advertisements.Advertisement:.cctor () ADSSSS:Start () (at Assets/Scripts/ADSSSS.cs:8)

Object reference not set to an instance of an object UnityEngine.Advertisements.Advertisement:.cctor () ADSSSS:Start () (at Assets/Scripts/ADSSSS.cs:8)

Can't add script behaviour CoroutineExecutor because it is an editor script. To attach a script it needs to be outside the 'Editor' folder. UnityEngine.Advertisements.Advertisement:.cctor () ADSSSS:Start () (at Assets/Scripts/ADSSSS.cs:8)

Can't add script behaviour ApplicationQuit because it is an editor script. To attach a script it needs to be outside the 'Editor' folder. UnityEngine.Advertisements.Advertisement:.cctor () ADSSSS:Start () (at Assets/Scripts/ADSSSS.cs:8)

NullReferenceException: Object reference not set to an instance of an object UnityEngine.Advertisements.Utilities.UnityLifecycleManager.Initialize () (at <91220002a2fd403abd0d44e0c6cd5f2c>:0) UnityEngine.Advertisements.Utilities.UnityLifecycleManager..ctor () (at <91220002a2fd403abd0d44e0c6cd5f2c>:0) UnityEngine.Advertisements.Advertisement.CreatePlatform () (at <91220002a2fd403abd0d44e0c6cd5f2c>:0) UnityEngine.Advertisements.Advertisement..cctor () (at <91220002a2fd403abd0d44e0c6cd5f2c>:0) Rethrow as TypeInitializationException: The type initializer for 'UnityEngine.Advertisements.Advertisement' threw an exception. ADSSSS.Start () (at Assets/Scripts/ADSSSS.cs:8)

Toto
  • 89,455
  • 62
  • 89
  • 125
  • never dealt with ads but I am pretty sure your plugin for ads is located in folder called /Editor you need to move that plugin outside that folder to anywhere else because Editor folder is special folder for unity and it does not compile – Nika Kasradze May 14 '21 at 07:13
  • Please use the correct tags! `unityscript` is or better was a JavaScript flavor like custom language used in early Unity versions and is long deprecated by now! Your script is clearly `c#`! – derHugo May 21 '21 at 18:00

1 Answers1

0

From Advertisement.Initialize

Manually initializes the advertisement system. Normally this is done from editor, and you should only call this method if you are using UnityAds with automatic initialization disabled.

the error you get is because certain scripts are placed in a folder called Editor. The content of these folders as the name suggests is supposed to be only used in the Unity Editor and will be skipped when building your application.

So in a build they won't be available anyway. Therefore Unity also forbids to use components from these folders in PlayMode.

Unity doesn’t allow components derived from MonoBehaviour to be assigned to GameObjects if the scripts are in the Editor folder.


To help further it would be required that you tell us the exact Unity and Advertisement versions you are using and how exactly you installed the Advertisement into your project. It is possible that the manual you are referring to is from a different version and things changed between them.

derHugo
  • 83,094
  • 9
  • 75
  • 115