Comments and answers for "Error CS0029 Help? (Screenshot of Exact Error)"http://answers.unity.com/questions/1263497/error-cs0029-help-screenshot-of-exact-error.html
The latest comments and answers for the question "Error CS0029 Help? (Screenshot of Exact Error)"Comment by stephen_george98 on stephen_george98's commenthttp://answers.unity.com/comments/1263549/view.html
Works like a charm! Thank you and thank you for teaching me something new today. I accepted your answerThu, 27 Oct 2016 22:32:18 GMTstephen_george98Comment by Namey5 on Namey5's commenthttp://answers.unity.com/comments/1263538/view.html
So you need to access each material individually? In which case you would use a material array, i.e.
using UnityEngine;
using System.Collections;
public class ChangeMaterial : MonoBehaviour
{
private Renderer rend;
private Shader differentShader;
public Material[] materials = new Material[31];
void Start ()
{
differentShader = Shader.Find ("Toon/Lit Outline");
rend = GetComponent<Renderer> ();
rend.enabled = true;
for (int i = 0; i < materials.Length; i++)
{
materials[i].shader = differentShader;
}
rend.sharedMaterials = materials;
}
}Thu, 27 Oct 2016 22:14:39 GMTNamey5Comment by stephen_george98 on stephen_george98's answerhttp://answers.unity.com/comments/1263532/view.html
That is why in my code (although not the greatest) I had line 20 and set the 30 materials in the Array. Is there a better way of doing that instruction that you know of?Thu, 27 Oct 2016 22:09:52 GMTstephen_george98Comment by stephen_george98 on stephen_george98's answerhttp://answers.unity.com/comments/1263531/view.html
Wow thank you for pointing out that I was actually creating a 31 dimensional array, my thinking was totally backward. And I get a NullReferenceException whenever I use your code. That is because I cannot now set the 30 Array elements (30 materials) in the Inspector.Thu, 27 Oct 2016 22:08:37 GMTstephen_george98Comment by Sergio7888http://answers.unity.com/comments/1263506/view.html
@stephen_george98 Your syntax is incorrect. See [Multidimensional Arrays (C# Programming Guide)][1]
[1]: https://msdn.microsoft.com/en-us/library/2yd9wwz4.aspxThu, 27 Oct 2016 21:36:01 GMTSergio7888Answer by Namey5http://answers.unity.com/answers/1263502/view.html
You are declaring a two-dimensional array, yet assigning it an apparent 31-dimensional array. The materials array in a renderer is a one-dimensional array, and as such does not need any commas. Not to mention, you are assigning an integer value to a material variable. You are also not actually doing anything in the for loop, just simply repeating the exact same line 31 times. The following is how you would go about doing this;
using UnityEngine;
using System.Collections;
public class ChangeMaterial : MonoBehaviour
{
private Renderer rend;
private Shader differentShader;
void Start ()
{
differentShader = Shader.Find ("Toon/Lit Outline");
rend = GetComponent<Renderer> ();
rend.enabled = true;
for (int i = 0; i < rend.sharedMaterials.Length; i++)
{
rend.sharedMaterials[i].shader = differentShader;
}
}
}Thu, 27 Oct 2016 21:31:54 GMTNamey5