【问题标题】:Unity emission isn't updating when I change the material当我更改材质时,Unity 发射没有更新
【发布时间】:2021-03-31 21:17:11
【问题描述】:

到目前为止,Emission 在我的游戏中有效 (see here)。 我试图让我的汽车每 1-5 秒闪烁一次颜色,由于某种原因,当我将材料更改为发射材料时,发射不起作用。

截图

Volume and Mesh renderer

Midway through the prosses of changing colors and emissions

Glow material

Normal material

这是我的代码,

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

public class Menu : MonoBehaviour {

    public Material glow_mat;
    public Material normal_mat;
    public float spin_speed;
    public SkinnedMeshRenderer renderer;
    public bool changing;
    public bool glow_change;
    public float change_amount;

    // Start is called before the first frame update
    void OnEnable() {
        StartCoroutine(changeColorStart());
    }

    IEnumerator changeColorStart() {
        yield return new WaitForSeconds(Random.Range(1, 5));
        glow_change = true;
        changing = true;
    }

    // Update is called once per frame
    void Update() {
        transform.Rotate(0, spin_speed * Time.deltaTime, 0);
        if (changing) {
            change_amount += Time.deltaTime * 2;//0.2s per 1
            if (change_amount > 1) {
                change_amount = 1;
            }
            renderer.materials[0].Lerp(glow_change ? normal_mat : glow_mat, glow_change ?  glow_mat : normal_mat, change_amount);
            if (change_amount == 1) {
                change_amount = 0;
                if (glow_change) {
                    glow_change = false;
                } else {
                    changing = false;
                    StartCoroutine(changeColorStart());
                }
            }
        }
    }
}

【问题讨论】:

    标签: unity3d rendering


    【解决方案1】:

    我得到了这个工作,如果你想知道你需要在重大更改后放置此代码,

    mat.SetColor("_EmissionColor", targetColor);//Or whatever material change you have.
    mat.EnableKeyword("_EMISSION");//This is a bug in unity
    

    我在统一文档here 上找到了答案。

    【讨论】:

      猜你喜欢
      • 2022-07-30
      • 2018-05-20
      • 1970-01-01
      • 2022-07-01
      • 2021-07-02
      • 2022-10-09
      • 2022-11-15
      • 2019-02-05
      • 1970-01-01
      相关资源
      最近更新 更多