- Home /
Highlight complex gameobject
I downloaded some characters here: https://www.assetstore.unity3d.com/#/content/122
I created a prefab out of them and I am creating copies of them in my game. I'd like to highlight one of them at a particular time (i.e. change their color when it is their turn). Since it's based on turn, it needs to be done programatically.
The prefab is soldier
and has a soldier_Military_Male_Lod_1
in its directory that has a shader. I can change the color of that shader manually or while previewing the game, but I'm not sure how to access it from within the script.
Seems like I would use GetComponentsInChildren
, but the name of the shader component is Soldier_D_1024_alt
, and I'm not sure how to reference this in the script.
How can I programmatically highlight / change the shader color of a prefab with its shader in its children?
Not enough info here for an exact answer. If you know the path from the top parent to the child that you want to access, you can use Transform.Find() to find the child transform. From there, you can access the renderer (Transform.renderer).
Transform doesn't seem to have a Find
method. What other information do you need?
Answer by tanoshimi · Dec 10, 2013 at 10:45 PM
How about this?
Renderer renderer = this.GetComponentInChildren<Renderer>() as Renderer;
Shader highlightedShader = Shader.Find("Toon/Basic Outline"); // Replace with whatever shader you want
renderer.material.shader = highlightedShader;