Hi i am pretty new to unity3D and porting my aktuell project from Java to Unity.
Now i have a problem and cant get the error.
I have a list that is made of a costum class witch holds some small data
when i try to acces the array stored in that class i get alyways the value 0 returned.
here is some code for bette understanding and sorry for the bad english.
The class that store the data
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class RoomTemplate
{
public int [,] room_map;
public List<Vector2i> door_list;
public int width;
public int height;
public RoomTemplate(int size_x, int size_y)
{
room_map = new int [size_x,size_y];
door_list = new List<Vector2i>();
this.width = size_x;
this.height = size_y;
}
}
Where the Roomtemplate is filled
public RoomTemplate loadRoom(Texture2D pixmap)
{
RoomTemplate room_template = new RoomTemplate(pixmap.width, pixmap.height);
for(int x = 0; x < pixmap.width; x ++)
{
for(int y = 0; y < pixmap.height; y ++)
{
if(pixmap.GetPixel(x, y).r == floor_color.x
&& pixmap.GetPixel(x, y).g == floor_color.y
&& pixmap.GetPixel(x, y).b == floor_color.z)
room_template.room_map[x,y] = 1; // floor
// allready checked here and it stores the right value at x,y
}
}
return room_template;
}
where it goes to
files = Resources.LoadAll("Dungeon Parts/Short");
foreach(Texture2D file in files)
{
pixmap = file as Texture2D;
short_floor_template_list.Add(room_template_loader.loadRoom(pixmap) as RoomTemplate);
}
generateMap(200, 200, 10, 30, 50, 75, 95,0);
where it is needed and return 0 at short_floor_template_list[0].room_map[x,y]
public int[,] generateMap(int map_width, int map_height ,int short_floor ,int long_floor ,int small_room,int large_room, int huge_room, int max_rooms)
{
int[,] map = new int[map_width,map_height];
if(max_rooms == 0)max_rooms = 499999999;
// for testing
for(int x = 0; x < short_floor_template_list[0].width; x ++)
{
for(int y = 0; y < short_floor_template_list[0].height; y ++)
{
Debug.Log("tile value = " + short_floor_template_list[0].room_map[x,y]);
map[x + map_width / 2,y + map_height / 2] = short_floor_template_list[0].room_map[x,y];
if(map[x,y] == 2)
{
GameObject wall = Instantiate(Resources.Load("Wall")) as GameObject;
wall.transform.position = new Vector3(x,1,y);
}
}
}
[code]