- Home /
change grass - tree texture at runtime
hello, which method to use to change the textures of trees and grass at runtime? is it possible?
Answer by flaviusxvii · Jul 06, 2012 at 04:51 PM
Asked and answered literally dozens of times. Google "unity3d change texture".
I know how to change texture on a normal object.
example:
var mytexture : Texture;
var myobj : GameObject;
function Update(){
myobj.renderer.material.mainTexture = mytexture;
}
Does NOT work on terrain.
Your question was about grass and trees. You said NOTHING about terrain.
Answer by jc_lvngstn · Jul 06, 2012 at 07:11 PM
Seems like you would have to update the original prefab of the tree, then tell the terrain to refresh. From memory, I think this involves a voodoo mix of
Reset the terrain heights. I normally set the heights giving it an empty array of height values. No heights are changed, but it forces the terrain to refresh. Partially. disabling and reenabling the terrain collider. Again...this is from memory. I don't have the exact sequence of steps in front of me.
I normally have to do something like this when I remove a tree, and need to update the terrain collider. I believe I have an answer here somewhere that has more info.
But, I can't guarantee that you can update the prefab on the fly like that, and the terrain automatically take notice. Good luck, if you figure it out please post your findings :) Sounds like you are changing things based on weather or season? If that is the case, you -could- create different prefabs for each tree, depending on the season, and tell the terrain to use those instead. I know for a fact that that would work!
Your answer
Follow this Question
Related Questions
grass with particle system 1 Answer
Why are textures disappearing when camera gets close? 1 Answer
Grass Textures of Terrain changing colors dinamically 2 Answers
Brush Size and Tree Deletion problems 0 Answers
My grass looks really weird. 0 Answers