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.
© 2024 OneMinuteCode. All rights reserved.