hi i attached to my background object a script but it does not load any sprite, in the sprite render a the sprite label apper “none” , anyone can tell me why? thanks
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Background : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
if (Input.GetKeyDown (KeyCode.A)) {
this.gameObject.GetComponent<SpriteRenderer> ().sprite = Resources.Load<Sprite>("home/marco/Desktop/img.png");
}
}
}
When using Resources, you don’t include the file extension.
If that doesn’t work, post a screenshot of the project folder where img.png is kept.
Also, I’m guessing that file’s not actually in a Resources folder either. If you want to use Resources.Load, the file has to be in a folder called “Resources” in your Unity project. If it’s a file on your desktop it’s not going to work. You will have to use the regular .NET File system to access it.
That looks like a proper directory on Mac/Linux, maybe.
I just looked at the docs, and they said that the path is relative to the Resources folder inside the assets folder.
Could be… just the fact that it has “Desktop” in it makes me think it’s actually a file on the desktop. If it’s in Resources/home/marco/Desktop then that’s fine.
StarManta the resource have to stay in the project folder?? i can’t call “external” resource? a… i’m using linux
this is the screenshot you asked …
Make a folder in there called “Resources” and put the file in there, then you can call:
Resources.Load<Sprite>("img");
Also, that dog is super cute. 
Ya, he moved it it seems. I didn’t think it was in Resources before. 
ty makeshiftwings , it works !! :))
Yeah. If you need to load an image that’s not in your project folder, you have to use UnityWebRequest with a file:// URL and a DownloadHandlerTexture.