How to change sourceimage of Image on Unity?

Hi how can i change source image of Image?
7414292--906875--upload_2021-8-13_11-2-38.png

My code here. But gets nullreferenceexception

    Image image;
    public Sprite newImage;
    private void Start()
    {
        image = GetComponent<Image>();
    }
    public void ChangeBackgroundMaterial()
    {
        image.sprite = newImage;

    }
  1. Find out what is null
  2. Find out why it’s null
  3. Fix it

3 simple steps.

My guess, image is null.

2 Likes

Problem solved