- Home /
Change material on multiple objects when nav mesh agent reaches waypoint
Hello, I am very new to Unity and know I am doing things very unorthodox, so I hope this makes sense! I created a bunch of different walls, all with the same material. A nav mesh agent navigates along a series of waypoints. All I want to do is change the material or shader of every wall every time the agent reaches certain waypoints. I have tried the following a number of different ways: public class mazeRend : MonoBehaviour {
private MeshRenderer _mazeRend;
private Shader shader1;
private Shader shader2;
private Shader shader3;
private Shader shader4;
// Start is called before the first frame update
void Start()
{
_mazeRend = GetComponentInChildren<MeshRenderer>();
shader1 = Shader.Find("Unlit/Texture");
shader2 = Shader.Find("Mobile/Diffuse");
shader3 = Shader.Find("Toon/Basic");
shader4 = Shader.Find("Standard");
_mazeRend.sharedMaterial.shader = shader1;
}
// Update is called once per frame
void Update()
{
}
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("char_1"))
{
_mazeRend.sharedMaterial.shader = shader2;
}
}
}
I have also tried indexing Material[] with an int = 0, and updating with Material[int++]. I have tried linking the above script with my characterController script, such as
if(characterController._currentTarget == waypoints[4]){_mazeRend.sharedMaterial.shader = shader2;}
When using colliders, I get a NullReference error and when linking scripts, nothing happens.
Also, all 4 shaders are attached to each wall.
Any help would be so so so much appreciated! Thank you anyone that offer any solutions/advice!!
Your answer

Follow this Question
Related Questions
Material doesn't have a color property '_Color' 4 Answers
Particle System: Material doesn't cover the entire sphere mesh 1 Answer
How to make a cube with metallic look and soft edges [pic included] 1 Answer
Use multiple materials? 1 Answer
Soft edge shader - Issues when objects using same material overlap 0 Answers