using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WallsTest : MonoBehaviour
{
public Transform prefab;
public float wallsSize;
public Vector3 wallsStartPosition;
private List<Transform> walls = new List<Transform>();
// Use this for initialization
void Start()
{
for (int i = 0; i < 4; i++)
{
Transform go = Instantiate(prefab);
go.transform.parent = transform;
go.transform.localPosition = wallsStartPosition;
walls.Add(go);
}
walls[2].transform.localPosition = new Vector3(wallsStartPosition.x + wallsSize, 0, wallsStartPosition.z + wallsSize);
walls[3].transform.localPosition = new Vector3(wallsStartPosition.x + wallsSize, 0, wallsStartPosition.z + wallsSize);
}
// Update is called once per frame
void Update()
{ // transform.localScale.z != wallsSize
if (walls[0].transform.position.x != wallsSize && walls[0].transform.localScale.z != wallsSize
&& walls[1].transform.position.x != wallsSize && walls[1].transform.localScale.z != wallsSize)
{
walls[0].transform.localScale += new Vector3(1, 1, 0);
walls[0].transform.localPosition += new Vector3(0.5f, 0.5f, 0);
walls[1].transform.localScale += new Vector3(0, 1, 1);
walls[1].transform.localPosition += new Vector3(0, 0.5f, 0.5f);
}
if (walls[2].transform.position.x != -wallsSize && walls[2].transform.localScale.z != -wallsSize
&& walls[3].transform.position.x != -wallsSize && walls[3].transform.localScale.z != -wallsSize)
{
walls[2].transform.localScale -= new Vector3(1, 1, 0);
walls[2].transform.localPosition -= new Vector3(0.5f, -0.5f, 0);
walls[3].transform.localScale -= new Vector3(0, 1, 1);
walls[3].transform.localPosition -= new Vector3(0, -0.5f, 0.5f);
}
}
}
The first problem is in the end the walls not same height and width. They are missed by 0.5
The walls values in the end:
Wall 0: X = 49.5 Y = 49.5 Z = 0
Wall 1: X = 0 Y = 49.5 Z = 49.5
Wall 2: X = 49.5 Y = 50 Z = 100
Wall 3: X = 100 Y = 50 Z = 49.5
How can i fix it so all the walls will be same height and width ?
Second problem is if there is a better way shorter way to write this code ?