How to load images using C# from UNI.T engine

Asked 2 years ago, Updated 2 years ago, 123 views

Unity Engine uses the C# code to create an image window on the screen I'd like to continue loading images stored in the Asset folder

If you know how to do it, please tell me ㅠ<

(I'd appreciate it more if you let me know the code.)

unity c# image

2022-09-22 13:11

1 Answers

How to change to code. The image field must be saved on Unity. Or you can use GameObject.Find and GetComponent.

using UnityEngine.UI;
public class NewBehaviourScript : MonoBehaviour {
    public Image image;
    // // Use this for initialization
    void Start () {
        Sprite newSprite =  Resources.Load <Sprite>("image");
        image.overrideSprite = newSprite;
    }
}

Assuming that the goal is to display it on the UI screen,

(1) Select the GameObject menu-UI-Image. There will be an object called Image under Canvas in the Hyeraki view.

(2) Prepare an image file. It must be in the Assets folder. If you select an image file, you can select the Texture Type from the selection menu at the top of the Inspector view. Change it to Sprite. Then press Apply at the bottom.

(3) With Image Game Object selected, you will see the Source Image item in the Inspector view. Drag&Drop the image file there, and it looks like this.


2022-09-22 13:11

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.