- Home /
Plot sprite from a string array on screen location
Hi, Apologies if this question is reappearing as I cannot find where my original question is.
From the question below you will understand that i am very new to UNITY :)
I have a string array
"BBBBBBBBBB",
"BPPPPPPPPB",
"BP000000PB",
"BP000000PB",
"BPPPPPPPPB",
"BBBBBBBBBB";
The purpose is that it will plot a border sprite if it see a "B" , a padding sprite if it sees a "P" and nothing if it is zero.
private void DrawBoundrySprites()
{
Vector3 pos = Vector3.zero;
for (int r = 0; r < grid.Length; r++)
{
for (int c = 0; c < grid[r].Length; c++)
{
pos = new Vector3(c, pos.y, pos.z);
if (grid[r][c] == "B")
{
Instantiate(borderTree, pos, Quaternion.identity, objWorld);
}
else if(grid[r][c] == "P")
{
Instantiate(padding, pos, Quaternion.identity, objWorld);
}
}
pos = new Vector3(0, r, pos.z);
}
DrawBoundrySprites function works fine but its pos variable starts from bottom up. Meaning, the fist line of "B"s in array draws at lower end of the screen.
And if I change the two lines of Instantiate code as follows (as part of trouble shooting):
if(r==0) Instantiate(borderTree, pos, Quaternion.identity, objWorld);
if(r==1) Instantiate(padding, pos, Quaternion.identity, objWorld);
both Sprites for borderTree and padding are drawn on top of each other.
I have faint idea that it may be because of how unity divides its screen coordinates but am unable to pin-point the issue.
Your answer

Follow this Question
Related Questions
How to check the current sprite in the image source? Unity 4.6beta20 1 Answer
Changing from Sprite Array to Game Objects 0 Answers
put every sprite frame in a array 1 Answer
Masking using Vector2 array 0 Answers
How do i change a sprite when another gameobject with the same prefab is colliding / is near 1 Answer