Search Unity

Use an Editor script to copy to clipboard

Discussion in 'Scripting' started by Tarzan111, Mar 17, 2016.

  1. Tarzan111

    Tarzan111

    Joined:
    Oct 8, 2014
    Posts:
    72
    Hi,

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

    My script :
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEditor;
    4. public class copyscript : MonoBehaviour {
    5.     public void CopyToClipboard( string str ){
    6.         EditorGUIUtility.systemCopyBuffer = str;
    7.     }
    8. }
    9.  
    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
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    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.
     
  3. andrew-fray

    andrew-fray

    Joined:
    Jul 19, 2012
    Posts:
    157
    In this situation you can use GUIUtility.systemCopyBuffer instead (Unity 2022.2.6).