欢迎光临
我们一直在努力

UGUI怎么获取Image,怎么动态的更换Image - 开发技术

    怎么动态来修改UGUI中的p_w_picpath呢,怎么来获取这个组件呢 ,首先我们需要在头文件里面定义一下 

我圈中的那***哪里,不能没办法获取到p_w_picpath组件

     using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.Sprites;
public class OnButton : MonoBehaviour {

   private Button button;
   private Image p_w_picpath;
    
    void Start () {

    button=this.GetComponent<Button>();
    p_w_picpath=this.GetComponent<Image>();

    }

 
    private void ButtonDown()
    {

    button.interactable=false;           p_w_picpath.overrideSprite=Resources.Load(”Textures/TechBlue/background”,typeof(Sprite))as Sprite;//这里就是修改他的图片,
    p_w_picpath.color=Color.red;

    }
}


最后记住,在图片哪里我们需要换一下类型,不然没办法修改他的图片

赞(0)
【声明】:本博客不参与任何交易,也非中介,仅记录个人感兴趣的主机测评结果和优惠活动,内容均不作直接、间接、法定、约定的保证。访问本博客请务必遵守有关互联网的相关法律、规定与规则。一旦您访问本博客,即表示您已经知晓并接受了此声明通告。