为什么会出现这样的错误 unity monetization

why such an error occurs unity monetization

我添加了 unity 货币化包然后我写了这个脚本:

using UnityEngine;
using UnityEngine.Advertisements;

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

然后在unity中出现这样的错误

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)

来自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.

您收到的错误是因为某些脚本位于名为 Editor 的文件夹中。顾名思义,这些文件夹的内容应该仅在 Unity 编辑器中使用,在构建应用程序时将被跳过。

所以在构建中它们无论如何都不可用。因此Unity也禁止在PlayMode中使用这些文件夹中的组件。

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


为了进一步提供帮助,您需要告诉我们您正在使用的确切 Unity 和 Advertisement 版本以及您如何将 Advertisement 安装到您的项目中。您所指的手册可能来自不同的版本,并且它们之间的内容有所不同。