【发布时间】:2021-03-31 21:17:11
【问题描述】:
到目前为止,Emission 在我的游戏中有效 (see here)。 我试图让我的汽车每 1-5 秒闪烁一次颜色,由于某种原因,当我将材料更改为发射材料时,发射不起作用。
截图
Midway through the prosses of changing colors and emissions
这是我的代码,
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());
}
}
}
}
}
【问题讨论】: