- Home /
How to reload a mainTexture to a mesh?
****Im trying to apply a different color and texture for a period of time on the mesh of characters in a fightgame.(like a subzero move) i would like to know how to reload the original texture that I have changed after few seconds.
Thanks for any advice.
using UnityEngine; using System.Collections;
public class meshcolor : MonoBehaviour {
public Color colorStart = Color.red;
public Color colorEnd = Color.green;
public float duration = 1.0F;
public Texture texture; //*the new texture*
void Update() {
foreach(GameObject fooObj in GameObject.FindGameObjectsWithTag("character"))
{
float lerp = Mathf.PingPong(Time.time, duration) / duration;
fooObj.renderer.material.color = Color.Lerp(colorStart, colorEnd, lerp);
fooObj.renderer.material.mainTexture = texture;
StartCoroutine(resetrender());
}
}
IEnumerator resetrender() {
yield return new WaitForSeconds(3);
foreach(GameObject fooObj in GameObject.FindGameObjectsWithTag("character"))
{
fooObj.renderer.material.color = Color.white; *// here I reset the material.color and its working in this way*
}
}
}
Answer by SkaredCreations · Dec 24, 2014 at 12:16 PM
Store them into own variables inside Start function
Thank you thats the way I think , now Im looking for how get the main texture of the object and furthermore how to store it. I think I can get the texture by this way?!
original_texture = fooObj.renderer.material.GetTexture ("_$$anonymous$$ainTex");
Your answer
Follow this Question
Related Questions
texture.width not returning actual image pixels 2 Answers
Scroll using material.mainTextureOffset makes the texture very distorted 1 Answer
texture "animation" sync with character problem [PAID] 0 Answers
Modifying material modifies the actual .mat file! 0 Answers
Change the texture on a material at runtime without creating an instance 1 Answer