I have in the Hierarchy a empty GameObject called it Walls
Then as childs of Walls i added 4 empty GameObjects
Then for each empty GameObject i added a child cube
For example if i give the size of the walls on the variable wallsSize to be 500 then it will build a 500x500 square.
The problem is when it’s doing the square some of the walls in another Y position.
For example the empty gameobject Walls is at position 33,0,0
But then if i take for example GameObject (1) or GameObject i see it’s Y position is -6
But if i take for example GameObject (2) or GameObject (3) i see they both Y position at 0
That make two walls smaller then the two others. Two walls at position 0 height and two at -6.
Not sure why and how to fix it.
I want all 4 walls GameObject , GameObject (1) , GameObject (2) , GameObject (3) to be at height 0 Y = 0
The script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Walls : MonoBehaviour
{
public Vector3 scaleFactor;
public float wallsSize;
public bool scaleDown = false;
private bool changepos = false;
private void Update()
{
if (scaleDown == false)
{
if (transform.localScale.x != wallsSize && transform.localScale.z != wallsSize)
{
transform.localScale += new Vector3(scaleFactor.x, scaleFactor.y, scaleFactor.z);
}
}
if (scaleDown == true)
{
if (changepos == false)
{
transform.position = new Vector3(transform.position.x + wallsSize,0, transform.position.z + wallsSize);
changepos = true;
}
if (transform.localScale.x != -wallsSize && transform.localScale.z != -wallsSize)
{
transform.localScale -= new Vector3(scaleFactor.x, scaleFactor.y, scaleFactor.z);
}
}
}
}