Unity通过脚本更改物体的材质

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Setmesh : MonoBehaviour
{
    /// <summary>
    /// 从面板获取物体的组件MeshRenderer
    /// </summary>
    public MeshRenderer mesh;
    // Start is called before the first frame update
    void Start()
    {
   
    }

    // Update is called once per frame
    void Update()
    {
        
    }
    /// <summary>
    /// 切换材质的函数
    /// </summary>
    /// <param name="mat">材质参数,从面板赋予</param>
    public void MeshRender(Material mat)//通过添加事件直接调用
    {
     
        mesh.material = mat;
    }
}

 

猜你喜欢

转载自blog.csdn.net/qq_52058429/article/details/126892321
今日推荐