Ok, after exhaustive searching, I still haven’t come up with an answer, which must be extremely obvious and easy, so apologies…
Two codes:
One is a gui which controls the material of the selected object.
At the moment all the objects, when selected go through the same array of Materials. However, I need each selected object to have it’s own array of Materials. To this end I have placed an array of materials on each object, with this code, called “TextureArray”
var textures : Material[];
How do I get the following script to access the above array on the selected object?
At the moment, when an object is clicked it sets itself as “selected” in this code…“MapControl”
static var selected : GameObject;
var arr : Material[];
var no = 0;
function OnGUI () {
if (GUI.Button (Rect (615,Screen.height - 30, 30, 30), ">>")) {
no += 1;
if (no >= arr.length) { no = 0; }
selected.renderer.material = arr[no];
}
if (GUI.Button (Rect (540,Screen.height - 30, 30, 30), "<<")) {
no -= 1;
if (no <=- arr.length) { no = 0; }
selected.renderer.material = arr[no];
}
GUI.Label(Rect(580,Screen.height - 20, 40, 30), "MAP");
}
Thank you.[/code]