Hi unity,
Im getting this error message:
error cs1061: Type ‘unityEngine.Component’ does not contain a definition for materials
does anyone know why i get this error?
this is my code:
using UnityEngine;
[AddComponentMenu("Rendering/SetRenderQueue")]
public class SetRenderQueue : 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<em>.renderQueue = m_queues*;*</em>
* }*
* }*
}
This is because you are accessing the renderer via the deprecated property “renderer” this property is now of type “Component” not of type “Renderer” This was done alongside a load of other similar properties like rigidbody to reduce coupling in the unity code base and make things a bit more modular.
What you need to do is either cast renderer to an appropriate type, or better yet, store an appropriate reference to it as a variable using GetComponent. for example. (Code done in notepad, may be slight syntax errors).
using UnityEngine;
[AddComponentMenu("Rendering/SetRenderQueue")]
public class SetRenderQueue : MonoBehaviour {
[SerializeField]
protected int[] m_queues = new int[]{3000};
private MeshRenderer m_renderer;
protected void Awake(){
m_renderer = GetComponent<MeshRenderer>();
Material[] materials = m_renderer.materials;
for (int i = 0; i < materials.Length && i < m_queues.Length; ++i){
materials<em>.renderQueue = m_queues*;*</em>
}
}
}