- Home /
How can i make the walls creation in the loop to be in slow speed ?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WallsTest : MonoBehaviour
{
// using a GameObject rather than a transform
public GameObject prefab;
public Vector3 wallsStartPosition;
public float width = 0;
public float height = 1;
public float length = 2;
public Camera wallsCamera;
void Start()
{
wallsCamera.transform.position = new Vector3(wallsStartPosition.x, wallsStartPosition.y + 100, wallsStartPosition.z - 235);
BuildWalls();
}
private void Update()
{
}
void BuildWalls()
{
for (int i = -2; i < 2; i++)
{
GameObject go = Instantiate(prefab);
go.transform.parent = transform;
Vector3 scale = Vector3.one;
Vector3 adjustedPosition = wallsStartPosition;
float sign = Mathf.Sign(i);
if ((i * sign) % 2 == 0)
{
adjustedPosition.x += (length * sign) / 2;
scale.x = width;
scale.y = height;
scale.z *= length + width;
}
else
{
adjustedPosition.z += (length * sign) / 2;
scale.x *= length + width;
scale.y = height;
scale.z = width;
}
adjustedPosition.y += height / 2;
go.transform.localScale = scale;
go.transform.localPosition = adjustedPosition;
}
}
}
Now i'm calling BuildWalls once in the Start so it's placing the 4 walls all at once.
But i want to call BuildWalls in the Update and to control the speed of the scaling/position of the walls so it will look like it's placing cube by cube...and not 4 walls at once. I want to see the walls creation.
Some public float variable so i can change and control the walls creation speed from very slow to very fast. When i say walls creation i mean like placing cube by cube...and not just placing the whole 4 walls at once slow or fast !
Answer by Glurth · Oct 14, 2017 at 05:45 PM
Here is a method to that in pseudo code:
Store the current time value in a private lastCreationTime variable, each time you create a wall. Create 1 wall in start.
Then in update, check that lastCreationTime value plus your public, user adjustable, timeInterval variable against the current time.
If the sum exceeds the current time, Create a wall, and reset your lastCreationTime to the current time.
I'm trying...$$anonymous$$aybe you could give me some example please ?