- Home /
Unity 5.6 error UnityEngine.Component' does not contain a definition for `materials' and no extension method `materials' of type `UnityEngine.Component' could be found. Are you missing an assembly reference?
Here is my script and getting error please give me solution its urgent and I am making AA FPS pls help me
/*
SetRenderQueue.cs
Sets the RenderQueue of an object's materials on Awake. This will instance
the materials, so the script won't interfere with other renderers that
reference the same materials.
*/
using UnityEngine;
[AddComponentMenu("Rendering/SetRenderQueue")]
public class Render : MonoBehaviour {
[SerializeField]
protected int[] m_queues = new int[]{3000};
protected void Awake() {
Material [] materials = renderer.materials;
for (int i = 0; i < materials.Length && i < m_queues.Length; ++i) {
materials[i].renderQueue = m_queues[i];
}
}
}
error
Assets/Scripts/Render.cs(20,37): error CS1061: Type UnityEngine.Component' does not contain a definition for
materials' and no extension method materials' of type
UnityEngine.Component' could be found. Are you missing an assembly reference?
Thanks in advance :) Urgent !!!
Answer by Bodhid · Aug 11, 2017 at 03:03 PM
change renderer in GetComponent<MeshRenderer>
or GetComponent<Renderer>
In this line (which is the only one with the word "renderer"):
$$anonymous$$aterial [] materials = renderer.materials;
replace renderer
with GetComponent<Renderer>()
. So the line reads:
$$anonymous$$aterial [] materials = GetComponent<Renderer>().materials;
Your answer
Follow this Question
Related Questions
Reflection bigger than actual gameobject. 0 Answers
Texture alpha doesn't scroll with offset 1 Answer
How to install new components in unity? 0 Answers
Rendering objects into another camera with a different material in HDRP 0 Answers
How to know if my Shader Graph is supported by the SRP Batcher? 1 Answer