- Home /
dosent work
hi community i wrote this script but it dosent update the text in the grid buttons do you have any ideas why this could happen? heres the code:
using UnityEngine; using System.Collections; using System.Collections.Generic;
public class TutorialInventar : MonoBehaviour {
public Rect [] gridRects= new Rect[50];
public int countRects=0;
Dictionary items = new Dictionary();
public string[] showNamesInGrid= new string[50];
int countItems=0;
void AddItems(){
items.Add("schwert","Schwert"); items.Add ("schild","Schild");
}
void OnGUI(){
for( int y=0; y<10; y++){ for(int x =0; x<5; x++){
if(countRects<49){
countRects++;
}
gridRects[countRects]= new Rect(0+60*x,0+60*y,60,60);
GUI.Button (new Rect(gridRects[countRects]),showNamesInGrid[countRects]);
} }
if(GUI.Button (new Rect(300,300,60,60),"schwert")){
countItems++; showNamesInGrid[countItems]=items["schwert"];
} }
void Start(){
AddItems ();
}
}
First, there's a problem with your Dictionary declaration - you have to specify what types the key and value of the dictionary are.
Please, do not post questions which are named "doesn't work" and please format your code.
Also, if you happen to post a question named "doesn't work", at least spell it correctly.
Your answer
![](https://koobas.hobune.stream/wayback/20220613074030im_/https://answers.unity.com/themes/thub/images/avi.jpg)