unity3D物体自发光代码

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

public class EmissionTest : MonoBehaviour
{
    private Renderer render;
    private Material BMX;
    // Start is called before the first frame update
    void Start()
    {
        render = GetComponent<Renderer>();  
        BMX = render.material;

        BMX.EnableKeyword("_EMISSION");  //开启自发光
        BMX.SetColor("_EmissionColor", BMX.color);  // 将自发光颜色设为材质球颜色
    }

    // Update is called once per frame
    private void OnDestroy()
    {
        BMX.DisableKeyword("_EMISSION");  //关闭自发光
    }
}

直接将代码挂载到带有材质球的物体上即可。

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐