Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

a small script to select a file from disk

Discussion in 'Scripting' started by antislash, Mar 11, 2019.

  1. antislash

    antislash

    Joined:
    Apr 23, 2015
    Posts:
    646
    hi,
    just in case someone is looking for how to pick a file from a button,
    here is a script that i found working
    take it FWIW

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using System.IO;
    6. using UnityEditor;
    7.  
    8. public class PickFile : MonoBehaviour
    9. {
    10.     public string FileName = "";
    11.  
    12.     // for use on a UI button
    13.     public void OpenFile()
    14.     {
    15.         FileName = EditorUtility.OpenFilePanel(FileName, "", "Image files,tif,png,raw");
    16.         print(FileName);
    17. }
    18.  
    19.  
    20. }
     
    Last edited: Mar 11, 2019
    Dekata and palex-nx like this.
  2. lucatrapasso_virtamed

    lucatrapasso_virtamed

    Joined:
    May 3, 2017
    Posts:
    1
    Just keep in mind that this doesn't work in build.
     
  3. antislash

    antislash

    Joined:
    Apr 23, 2015
    Posts:
    646
    didn't try it . i have a code that takes OS in account (win/mac).. but didn't build it.
    if you have any workaround i'd take it.