how to get a material commponnent with spcipic shader throw script

i want to get this material inside a script i was writing

Material mat = cloudMesh.GetComponent < Material > ();

and it say’s :

MissingComponentException: There is no ‘Material’ attached to the “CloudSystem” game object, but a script is trying to access it.
You probably need to add a Material to the game object “CloudSystem”. Or your script needs to check if the component is attached before using it.
UnityEngine.Material.SetTexture (System.String propertyName, UnityEngine.Texture texture) (at C:/buildslave/unity/build/artifacts/generated/common/runtime/ShaderBindings.gen.cs:231)
UnityEngine.Material.set_mainTexture (UnityEngine.Texture value) (at C:/buildslave/unity/build/artifacts/generated/common/runtime/ShaderBindings.gen.cs:185)
ManagerScript.Start () (at Assets/SpiderGame/Script/StartLevel/ManagerScript.cs:31)

Actually Material Component is not a class, so you can not get it like this. You can get material by firstly getting the MeshRenderer and then get its materials. eg
c# code :

50705-capture.png

Hope this will help :slight_smile: