Home > Software design >  Unity: Game Object Changes Material after a time delay
Unity: Game Object Changes Material after a time delay

Time:10-03

Essentially, I would like to have a Unity game object change materials after a specified time delay.

CodePudding user response:

Your code should be like this: x = does not interfere

    using UnityEngine;
      using Unity;
      using System.Collections;
      using System.Collections.Generic;
Class x: MonoBehaviour{
float Time;
float TimeWanted = x;
Color color;
if your game's 2D:
SpriteRenderer colorMaker;
if not:
Mesh colorMaker;
void Start(){
if your game's 2D:
colorMaker = GetComponent<SpriteRenderer>();
color = colorMaker.color;
if not:
colorMaker = GetComponent<Mesh>();
color = colorMaker.color;

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

}

}
  • Related