当我更改 material 时,Unity 发射没有更新
Unity emission isn't updating when I change the material
到目前为止,发射在我的游戏中有效 (see here)。
我试图让我的车每 1-5 秒闪烁一种颜色,出于某种原因,当我将我的 material 更改为发射 material 时,发射不起作用。
截图
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());
}
}
}
}
}
我已经开始工作了,如果您想知道需要在 material 更改后放置此代码,
mat.SetColor("_EmissionColor", targetColor);//Or whatever material change you have.
mat.EnableKeyword("_EMISSION");//This is a bug in unity
我在统一文档中找到了答案,here。
到目前为止,发射在我的游戏中有效 (see here)。 我试图让我的车每 1-5 秒闪烁一种颜色,出于某种原因,当我将我的 material 更改为发射 material 时,发射不起作用。
截图
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());
}
}
}
}
}
我已经开始工作了,如果您想知道需要在 material 更改后放置此代码,
mat.SetColor("_EmissionColor", targetColor);//Or whatever material change you have.
mat.EnableKeyword("_EMISSION");//This is a bug in unity
我在统一文档中找到了答案,here。