目次
はじめに
uGUIの「Image」では「Renderer」 や「SpriteRenderer」のように「sharedMaterial」ができなかったので、Awakeでベースとなるマテリアルを複製して対応しました。その時のサンプルです。

こちらのアセットを使用しています。
あわせて読みたい


【Unity-asset】All In 1 Sprite Shader の紹介
はじめに 「All In 1 Sprite Shader」を紹介します。スプライトにエフェクトを掛けたければ、このアセット1つで概ね条件は満たすのではないでしょうか。 https://www.yo...
サンプル
元の状態

サンプルコード
using UnityEngine;
using UnityEngine.UI;
public class Temp : MonoBehaviour
{
//ベースにするマテリアル
[SerializeField] Material mat;
//ベースマテリアル複製代入用
Material[] mats = new Material[5];
//複製したマテリアルを割り当てるImage
[SerializeField] Image[] img = new Image[5];
void Awake()
{
//マテリアルを複製
for(int i = 0; i < mats.Length; i++)
{
mats[i] = new Material(mat);
}
}
void Start()
{
//マテリアルを割り当てて色を変更
img[0].material = mats[0];
img[0].color = Color.red;
mats[0].DisableKeyword("DOODLE_ON");
img[1].material = mats[1];
img[1].color = Color.blue;
mats[1].SetInt("_HandDrawnAmount",10);
img[2].material = mats[2];
img[2].color = Color.yellow;
mats[2].SetFloat("_HandDrawnSpeed",2.5f);
img[3].material = mats[3];
img[3].color = Color.green;
mats[3].DisableKeyword("DOODLE_ON");
img[4].material = mats[4];
img[4].color = Color.magenta;
mats[4].SetInt("_HandDrawnAmount",7);
mats[4].SetFloat("_HandDrawnSpeed",5f);
}
}
結果

あわせて読みたい


【Unity】おすすめアセット一覧 簡単に紹介します
日頃お世話になっているUnity Asset Store のおすすめアセット達を一気にざっくり紹介します(五十音順) アセットは開発期間の短縮や学習にも繋がるので、セールなどを...