32 lines
982 B
C#
32 lines
982 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
[ExecuteInEditMode] //在编辑模式下执行
|
|
public class 全局材质脚本 : MonoBehaviour
|
|
{
|
|
public Transform targetObject; //目标物体
|
|
public Color[] color = new Color[2]; //定义一个颜色数组,存储两个颜色
|
|
// Start is called before the first frame update
|
|
void Awake()
|
|
{
|
|
Material globalMaterial = targetObject.GetComponent<Renderer>().sharedMaterial; //获取目标物体的材质
|
|
Vector4[] colors= new Vector4[color.Length]; //创建一个Vector4数组,用于存储颜色
|
|
for(int i = 0; i < color.Length; i++)
|
|
{
|
|
colors[i] = new Vector4(color[i].r, color[i].g, color[i].b, color[i].a);
|
|
}
|
|
globalMaterial.SetVectorArray("_Colors", colors); //设置全局材质的颜色参数
|
|
}
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
}
|