- Home /
arrays / textures help
ok i have 2 arrays lets say
x:GameObject[] = new GameObject[4]
and then i have
y:Texture[] = new Texture[4]
how do i access the gameObjects Textures in "x" to display them in "y".
sorry, just trying my best to do scripting BTW its in javascript,
thanks in advance to those who will answer.
Answer by save · Sep 08, 2012 at 08:17 AM
To access an object's main texture you go through the renderer's material.
for (var i = 0; i<x.Length; i++) {
y[i] = x[i].renderer.material.mainTexture;
}
You can also go by the property name in the shader by using the GetTexture-function:
var tex : Texture = renderer.material.GetTexture ("_BumpMap");
Remember that the array y doesn't have to be public, you could make it static or private (depending on your need for access level) and resize it before you iterate through the x array.
y = new Texture[x.Length];
dude have an error that says : "UnassignedReferenceException: The variable x of 'Js_Test' has not been assigned. You probably need to assign the x variable of the Js_Test script in the inspector." what to do?
What it means is that you haven't assigned the variable x (there's nothing in the array or you're trying to point to an element that isn't present).
Have you assigned the variable in the Inspector? If it's static have you declared a new GameObject[] and filled the array? Else are you sure you have an element where you point to the array? - The last thing often happens when stopping rule is larger than the actual elements in the array
x = new GameObject[10]; //0 - 9
var someNumber = 10; //0 - 10
for (var i = 0; i<someNumber; i++)
Your answer
Follow this Question
Related Questions
Resources.Load Problem 1 Answer
How do I texture objects in an array with different textures? 1 Answer
Can't add GameObjects to ArrayList 1 Answer
Keep adding targets to a list 2 Answers
How do I check multiple gameObjects transform positions? 3 Answers