Change the UI image using script in unity c#

后端 未结 4 577
走了就别回头了
走了就别回头了 2021-01-24 04:58

I want to change the UI image in random order. I have a gameobject in UI(canvas) containing Image component and it has nul

4条回答
  •  醉酒成梦
    2021-01-24 05:37

    You can also just use Image if you are in Unity 2017.3 (not sure if this works for older versions). For example:

    using UnityEngine.UI;
    -----
    public Image ObjectwithImage;
    public Sprite spriteToChangeItTo;
    
    void Start () {
            ObjectwithImage.sprite = spriteToChangeItTo;
        }
    

    Works great for me.

提交回复
热议问题