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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

can you Load image from outside of the resources folder?

Discussion in 'Scripting' started by Existingman, Jul 17, 2015.

  1. Existingman

    Existingman

    Joined:
    Dec 23, 2013
    Posts:
    4
    I'm developing my game-editor as a windows forms project, and my game-player as a Unity Project.
    Both of these applications Load the same Game Data, either for editing or for testing.
    Therefore, I find it conceptually irritating to have to locate the game-data inside of the Untity Project resources folder.
    I've located my game-data folder outside of both of the project folders.
    I can load all of my data files using the C# file framework.
    The only files I can't load are the image files because (as far as I know) they have to be loaded using the unity resources.load method if you want to use the images in a unity application.

    Is there a way I can load images from my hard drive to use as textures in unity, without placing them inside of the resources folder?
     
  2. runner

    runner

    Joined:
    Jul 10, 2010
    Posts:
    865
  3. hameed-ullah-jan

    hameed-ullah-jan

    Joined:
    Sep 24, 2014
    Posts:
    7
    Hi, i used this code for txt file, you can just replace the text file by your image file, hope it will help.

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using System.IO;
    using UnityEngine.UI;

    public class ReadingFile : MonoBehaviour {
    StreamReader _textreader;
    public Text mytext;
    string text = "";
    public string url = "file://c:/Users/Research-PC/Desktop/textEXP.txt";
    // Use this for initialization
    void Start () {
    //StartCoroutine(LoadFile ());

    }

    // Update is called once per frame
    void Update () {
    StartCoroutine(LoadFile ());
    }

    IEnumerator LoadFile()
    {
    using (WWW www = new WWW(url))
    {
    yield return www;
    text = www.text;
    Debug.Log (text);
    mytext.text = text;

    }
    }
    }