A
A
a16a2017-04-13 19:13:00
C++ / C#
a16a, 2017-04-13 19:13:00

How to upload an image using sprite?

Hello.
The picture is in the main. I also changed them to "Sprite 2D and UI" and changed the mod to "Single"
Then I wrote the following in the code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ServerImg : MonoBehaviour {

    public Image img1;

  void Update () {
        img1.sprite = Resources.Load<Sprite>("2");
        // img1.GetComponent<Image>().overrideSprite = Resources.Load<Sprite>("2");
    }
}

The same created cells are all pointed to their place.
But when everything starts, the picture remains unloaded. And if I initially specify a picture and during the execution, the first picture flies but is not replaced by the desired one.
What did I miss?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daniil Basmanov, 2017-04-14
@a16a

To get started, pull the sprite replacement from the update, put it in Awake or Start. Then check with a debugger that you really have something loaded from resources. Everything else should work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question