Answer the question
In order to leave comments, you need to log in
Why does Resources.Load() return null?
The code:
Sprite pistolSprite;
GameObject pistol;
public string pistolPath = "Sprites/Pistols/pistol";
public int damage;
void Start () {
pistolSprite = (Sprite)(Resources.Load (pistolPath, typeof(Sprite)));
if (pistolSprite == null)
Debug.Log ("Pistol sprite wasnt found");
pistol = new GameObject("pistol");
pistol.AddComponent<SpriteRenderer>().sprite = pistolSprite;
}
void Update () {
pistol.transform.position = new Vector3 (transform.position.x, transform.position.y, 0f);
pistol.transform.rotation = transform.rotation;
}
Answer the question
In order to leave comments, you need to log in
pistolSprite = Resources.Load <Sprite> (pistolPath);
//или если несколько внутри то
Sprite[] pistolSprites = Resources.Load <Sprite> (pistolPath);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question