I'm trying to make an array of materials to cycle through depending on a trigger. I have the trigger figured out but am unclear on the datatype. Would I make an array of strings and reference the names of the materials? I'm brand new to C# (but have worked a good bit in Processing) so help would be greatly appreciated. Thanks in advance.
You can make and use an array like this: Code (csharp): public Material[] materials; private int currentMat = 0; void Update() { if (Input.GetKeyDown(KeyCode.Space) ) { //or whatever your trigger is currentMat = (currentMat + 1) % materials.Length; GetComponent<Renderer>().material = materials[currentMat]; } }
And if you make just about any Unity type public, such as a Material, you can drag the materials straight into the Inspector slots it will make for you. Clicking the slot will even "pulse" the real asset. You could use save names and use Resources.Load("assetName") to grab the materials, which is what I think you were suggesting, but making Inspector links is almost always easier.