Use an Editor script to copy to clipboard

Hi,

I’m trying to copy to clipboard (for ios & Android) a string when a player click on “Copy” button.

My script :

using UnityEngine;
using System.Collections;
using UnityEditor;
public class copyscript : MonoBehaviour {
    public void CopyToClipboard( string str ){
        EditorGUIUtility.systemCopyBuffer = str;
    }
}

I have to put my script in “Editor” Folder because i’m using UnityEditor.

It’s actually the first time i have to use a script in Editor folder, i don’t know how to launch my public function.
I can’t attach my script to a GameObject because it’s in Editor Folder…

How to use my script now?

Thanks

You can’t use editor based functions “in” your game. Editor scripts are specifically about altering the unity editor to give you more functionality whilst developing games.

In this situation you can use GUIUtility.systemCopyBuffer instead (Unity 2022.2.6).