unity 3D物体自发光代码

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");  //关闭自发光
    }
}

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

猜你喜欢

转载自blog.csdn.net/weixin_44099953/article/details/127730040
今日推荐