Above is my game. Dark blue rectangle is a room - it is made up of one empty game object as a parent and 4 children sprites that are separate lines with their own 2d box colliders.
I want my room to shrink either vertically or horizontally or both when I play the game as time passes by. The problem is that when I shrink the room the parent seen in the hierarchy above, the lines that don’t “shorten” become squashed and look practically invisible. I want all sides to retain their thickness.
When I shrink the two lines seperately without scaling the parent. The thickness is retained but the two other lines do not shift up and join the shortened lines and it no longer looks like a box.
Script I used to shrink the room:
public class shrinkScript : MonoBehaviour {
public const float timer = 10f; //fixed value for how long it must be counting down. helps reset timer.
public float countDown; //time that changes
public float shrinkRateY; //speed at which it shrinks (vertical length of room)
float RoomY;
bool gameOver;
// Use this for initialization
void Awake() {
RoomY = transform.localScale.y;
countDown = timer;
shrinkRateY = (RoomY / countDown) * Time.deltaTime;
}
// Update is called once per frame
void Update () {
if (countDown > 0) {
countDown -= Time.deltaTime;
float scaleY; //stored the scale of the gameObject's x co-ordinate in a variable
scaleY = Mathf.Clamp(RoomY, 0.05f, 0.9943201f);
transform.localScale -= new Vector3(0, shrinkRateY,0);
}
}
}
Is there any possible way to achieve this?
PS: I want the room to shrink in-game with a script attached and allow the two other sides whose scale isn’t being changed to move up.
Many thanks,