简体   繁体   English

Unity: 游戏 Object 延迟一段时间后更改材质

[英]Unity: Game Object Changes Material after a time delay

Essentially, I would like to have a Unity game object change materials after a specified time delay.本质上,我想在指定的时间延迟后让 Unity 游戏 object 更改材料。

Your code should be like this: x = does not interfere.你的代码应该是这样的:x = does not interfere。 Make sure to add a material by right-clicking in the asset-viewer(in a 3D game).确保通过右键单击资产查看器(在 3D 游戏中)来添加材料。 // means comments, you don't have to put this in your code. // 表示注释,您不必将其放入您的代码中。 Only select the option your game applies.只有 select 选项适用于您的游戏。

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



Class x: MonoBehaviour{
float timer;
float TimeWanted = x(number);
Color color;


//if your game is 2D:
SpriteRenderer colorMaker;
//if not:
Renderer colorMaker;


void Start(){
//if your game is 2D:
colorMaker = GetComponent<SpriteRenderer>();
color = colorMaker.color;
//if not:
colorMaker = GetComponent<Renderer>();
color = colorMaker.color;

}
void Update(){
timer+=1*Time.deltaTime;
if(timer>=TimeWanted){
color = Color.blue;
timer=0;
}
colorMaker.color = color;

}

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM