I am working on creating a list of wall coordinates for my game and when I attempt to add the new wall item to the list of walls and it always overwrites every value in the list. Can someone look at my function and figure out what I’m doing wrong, please.
public void Start()
{
wallList = new List ();
}
public void Start()
{
wallList = new List<WallItem> ();
}
private void AddWalls()
{
//make a temporary wall item
WallItem tempWallLeft = new WallItem();
WallItem tempWallRight = new WallItem ();
//add more walls to get below the bottom y
while (wallY < c_wallBottomY)
{
//drop down to the next row
wallY += wallHeight;
//vary the x to give the cave wall some texture and challenge
float step = c_wallMinXStep + Random.Range (c_wallMinXStep, c_wallMaxXStep);
float r = Random.Range (0, 2);
if(r == 0)
{
step *= -1;
}
wallX += step;
wallX = Mathf.Max (c_wallXMargin + wallDistance/2, Mathf.Min (wallX, Screen.width - c_wallXMargin - wallDistance/2));
//add left side wall piece
tempWallLeft.x = wallX - wallDistance/2;
tempWallLeft.y = wallY;
wallList.Add (tempWallLeft);
//Debug code
//Debug.Log ("wallX is " + wallX + " wallY is " + wallY);
Debug.Log ("tempWallLeft.x = " + tempWallLeft.x + " tempWallLeft.y = " + tempWallLeft.y);
//add right side wall piece
tempWallRight.x = wallX + wallDistance/2;
tempWallRight.y = wallY;
wallList.Add(tempWallRight);
//debug code to count # of walls
//Debug.Log ("wallY is " + wallY);
Debug.Log ("tempWallRight.x is " + tempWallRight.x + " tempWallRight.y is " + tempWallRight.y);
//Debug.Log ("numWalls is " + numWalls);
//Debug.Log ("wallHeight is " + wallHeight);
//more debug code
for (int i = 0; i < wallList.Count; i++)
{
Debug.Log ("wallList[" + i + "].x = " + wallList_.x + " wallList[" + i + "].y = " + wallList*.y);*_
* }*
}
}