- Home /
Can you set a string length when declaring it to a certain other number?
Need to set a texture[] variable to be the length of a game object[] variable. How do I do that? I thought I could just use lists and resize it in start ie
var items : List.<GameObject>;
var icons : List.<Texture>;
icons.Count = items.Count; // need something like this in Start function
this works to set the length, but I'm using it for a gui selection grid and get a console error at this line
lineupInt = GUI.SelectionGrid (Rect (0 , 0, boxwidth, boxheight), lineupInt, icons, 3);
the setup I have is to make a selection grid representing the player's inventory items icons.
Please DO NOT suggest arrays. I'm trying to get off using them. Thanks
CE0023: No appropriate version of 'UnityEngine.GUI.SelectionGrid' for the argument list '(UnityEngine.Rect, int, UnityEngine.texture[], int)' was found.
Trying to not use arrays in program$$anonymous$$g is akin to trying not to see an advertisment downtown. Arrays are everywhere, often hidden... List
uses an array internally.
$$anonymous$$aybe you mean you were using an array before and now want to use something else. In this case, List
is a good choice.
Answer by superventure · Jan 25, 2014 at 05:02 AM
System.Array.Resize. (icons, items.Length);
Answer by Fabkins · Jan 25, 2014 at 01:21 AM
i think you are trying to use the selection grid with these arguments:
static function SelectionGrid(position: Rect, selected: int, images: Texture[], xCount: int): int;
My guess is that argument 3 is the problem. Its supposed to be an array of Textures and you've made it a list of no particular type. Whether you want to use arrays or not, that method requires an array of textures and thats what you are going to have to give it.
(im assuming lineupInt is indeed an int)
Darn. I was trying to bypass having to set the texture[] length in the inspector to be the length of another specific string automatically. Do you know if you can set it that way when declaring it? Something like var icons : Texture[] = obs.length?
Your answer
Follow this Question
Related Questions
Javascript Endless 3D Array 0 Answers
A node in a childnode? 1 Answer
Make the audio manager select from an array of sounds 1 Answer
List all children in array? 5 Answers