holding GUITextures in a array? and changing the size from script?

I want to make a array holding GUItextures and I dont know how to come about this… I Know java I think its start time I learn c# so I started off good and I am stuck here… well here is the code:

`using UnityEngine;
using System.Collections;

public class MainMenu : MonoBehaviour {
	public int[] TrackPictures = new int[2] {3, 4};
	public GUISkin myGUIskin;
	private int Track = 0;
	public int NumberOfTracks = 9;
	private int Number1More = 10;
	// Use this for initialization
	void Start () {
	TrackPictures = NumberOfTracks;
	//Makes sure that NO one make the "NumberOfTracks" go under "-"
		if(NumberOfTracks <= 0) {
			NumberOfTracks = 9;
	//Make Sure that "Number1More" is set 1 more then the "NumberOfTracks"
	Number1More = NumberOfTracks;
	Number1More += 1;
	// Update is called once per frame
	void Update () {
	void OnGUI () {
	//Sets the GUI skin
	GUI.skin = myGUIskin;	
		//If you click on this GUI buttn
		if(GUI.Button (new Rect(0, 0, 150, 30), "Start Game")) {
		//This GUI Box shows you what track you are at right now
		GUI.Box (new Rect(20, 30, 150, 30), "Track: " + Track);
		//If you click on this GUI buttn
		if(GUI.Button (new Rect(0, 30, 30, 30), "<")) {
			if(Track >= 1) {
				Track -= 1;
			if (Track == 0) {
				Track = NumberOfTracks;
		//If you click on this GUI buttn
		if(GUI.Button (new Rect(160, 30, 30, 30), ">")) {
			if(Track <= NumberOfTracks) {
				Track += 1;
			if (Track == Number1More) {
				Track = 0;

so yeah there it is and what I was hoping I could do was make it so where on void start the size of the array would change to “NumberOfTracks” and all you had to do was enter the GUItextures and then I would just set it up from there… I hope you know what i mean

well thanks :smiley:

You can implement a function that grabs the new size of the array, makes a new one of that size, and the brings over the old array to the new one, and finally assigns the new one to the original variable… (psst…don’t do this, keep reading)


You can take advantage of existing class that do this for you. If you import that namespace System.Collections.Generic you will have access to the List object which, if you’re from the Java world, is pretty exact to ArrayList in that it’s a collection that’s size can expand without headache.

Here’s how you could use it:

Using System.Collections.Generic;

public class YourClass {
   // instead of public int[] TrackPictures
   public List<int> TrackPictures;
   void Start() {
     TrackPictures.Add(314); // examples...


This avoids you having to reinvent the wheel and keeps your code specific that what it’s supposed to do. Here’s all what List can do: MSDN Documentation

Further: Unity has buit-in support for lists in the Editor view and will appear the same as an array does. So now you have no excuses :stuck_out_tongue:

Ohh yeah lol thanks. XD