怎麼動態來修改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;
}
}
最後記住,在圖片哪裏我們需要換一下類型,不然沒辦法修改他的圖片