This commit is contained in:
Mrhongxing committed 2026-09-07 23:14:10 +08:00
commit 5271663439
56 files changed
+3039

No files matched your search

+31
View File
@@ -0,0 +1,31 @@
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()
{
}
}