Need help with an image path script
So im using this script to set an image from my pc to a UI.Image and i have multiple such Images on the canvas so basically im trying to set multiple images to a texture from my PC but when i try to do so the first image is set perfectly but when i try to set the second one the first one also changes to the second image i wanted to use. I want all pictures to be set separately and not copy the next one. Here is the script:
using System.Collections; using System.Collections.Generic; using UnityEngine; using System; using UnityEngine.UI;
public class image_handler : MonoBehaviour {
public string path;
public Texture2D tex;
public Sprite spriteSet;
public GameObject objectToSetSprite;
public GameObject addButton;
public GameObject removeButton;
private bool picSet;
private void ChoosePic ()
{
path = UnityEditor.EditorUtility.OpenFilePanel ("Bild wählen.", "", "png");
if (path.Length != 0 && picSet == false)
{
WWW www = new WWW ("file:///" + path);
www.LoadImageIntoTexture (tex);
spriteSet = Sprite.Create (tex,new Rect (0, 0, tex.width, tex.height),new Vector2 (0.5F, 0.5F));
objectToSetSprite.GetComponent<Image> ().enabled = true;
objectToSetSprite.GetComponent<Image> ().overrideSprite = spriteSet;
tex = null;
path = null;
}
addButton.SetActive (false);
removeButton.SetActive (true);
picSet = true;
}
public void RemovePic ()
{
objectToSetSprite.GetComponent<Image> ().enabled = false;
addButton.SetActive (true);
removeButton.SetActive (false);
picSet = false;
}
}
Your answer
Follow this Question
Related Questions
Get a single texture from multiply one (from atlas) 1 Answer
Same animation from multiple spritesheets 1 Answer
Unity graphic bug ? 0 Answers
Unity display image from assets folder 0 Answers
World Space UI and Sprite Renderer doesn't render correctly,World Space UI doesn't render correctly 0 Answers