Studio GuideWorld SDK Guide
Log In
World SDK Guide

How to use #if UNITY_EDITOR when checking RuntimePlatform

While developing, there are times when you need to check whether the current script is running in the Unity Editor or mobile.

You can check whether it is running in the Unity Editor with the following example code.

import { ZepetoScriptBehaviour } from 'ZEPETO.Script'

export default class CheckPlatform extends ZepetoScriptBehaviour {

    Start() {
        
        // Check if the code is running inside the Unity Editor
        if (Application.isEditor) {

            // Log a message that the code is running in the Unity Editor
            console.log("This is Unity Editor");
        } else {

            // If the code is not running in the Unity Editor, log a different message
            console.log("It's not the Unity Editor");
        }
    }
}

👍

Tips

You can check various platform environments as well as the Unity Editor.

import { ZepetoScriptBehaviour } from 'ZEPETO.Script'

export default class CheckPlatform extends ZepetoScriptBehaviour {

    Start() {

        // Check if the application's platform is equivalent to the Windows Editor
        if(Application.platform == RuntimePlatform.WindowsEditor) {

            // If it's the Windows Editor, log the corresponding message to the console
            console.log("This is WindowsEditor");
        }else if (Application.platform == RuntimePlatform.OSXEditor) {

            // If it's the OSX Editor, log the corresponding message to the console
            console.log("This is OSX Editor");
        }
    }
}
  • For more information about RuntimePlatform, please refer to the following link.

https://docs.unity3d.com/2020.3/Documentation/ScriptReference/RuntimePlatform.html