ogsirus 0 C# Developer

Hi All,

I have a game which I'm implementing parallax scrolling which is currently looping infinite. Is there a way I can pause the loop for x amount of time, or even stop the loop completely after x amount of time.

Here a bit of my code so far:

    public Vector2 speed = new Vector2(10, 10);
        public Vector2 dir = new Vector2(-1, 0);
        public bool isLinkedToCamera = false;
        public bool isLooping = false;

        private List<Transform> bgPart;
        // Use this for initialization
        void Start ()

        {
            if (isLooping)
            {
                bgPart = new List<Transform>();


                for (int i = 0; i < transform.childCount; i++)
                {
                    Transform child = transform.GetChild(i);
                    if (child.renderer != null)
                    {

                        bgPart.Add(child);

                    }
                }
                bgPart = bgPart.OrderBy(t => t.position.x).ToList();
            }

        }

        // Update is called once per frame
        void Update ()
        {

            Vector3 move = new Vector3(
                speed.x * dir.x, speed.y * dir.y, 0);
            move *= Time.deltaTime;
            transform.Translate(move);
            if (isLinkedToCamera)
            {
                Camera.main.transform.Translate(move);
            }
            if (isLooping)
            {
                Transform firstchild = bgPart.FirstOrDefault();
                if (firstchild != null)
                {
                    if (firstchild.position.x < Camera.main.transform.position.x)
                    {
                        if (firstchild.renderer.isVisibleFrom(Camera.main) == false)
                        {
                            Transform lastchild = bgPart.LastOrDefault();
                            Vector3 lastpos = lastchild.transform.position;
                            Vector3 lastsize = (lastchild.renderer.bounds.max - lastchild.renderer.bounds.min);

                            firstchild.position = new Vector3(lastpos.x + lastsize.x,
                                firstchild.position.y, firstchild.position.z);

                            bgPart.Remove(firstchild);
                            bgPart.Add(firstchild);
                        }
                    }
                }
            }