Beispiel #1
0
        //Display a Random Prefab and position it at initialPosition return the x coordinate for the right bound
        private BackGroundElement DisplayRandomPrefab(Vector3 initialPosition, BackGroundInsertionDirection direction)
        {
            int randomIndex = 0;

            if (prefabsPool.Count == 0)
            {
                Debug.LogError("You need at least one prefab in the elements list.");
            }
            else if (prefabsPool.Count > 1)
            {
                randomIndex = Mathf.Abs(Random.Range(0, prefabsPool.Count));
            }

            //The element that will be rendered
            BackGroundElement renderedObject = prefabsPool[randomIndex].GetAvailableObject();

            renderedObject.DisplayAtPosition(initialPosition, direction);

            if (direction == BackGroundInsertionDirection.Right)
            {
                elementsOnScreen.Add(renderedObject);
            }
            else
            {
                elementsOnScreen.Insert(0, renderedObject);
            }

            return(renderedObject);
        }
Beispiel #2
0
        public void DisplayAtPosition(Vector3 pos, BackGroundInsertionDirection direction)
        {
            //We are placing the obect based on his center so we /2.0f the width

            int directionFactor;

            if (direction == BackGroundInsertionDirection.Right)
            {
                directionFactor = 1;
            }
            else
            {
                directionFactor = -1;
            }
            Vector3 newPos = new Vector3(pos.x + ((width / 2.0f) * directionFactor), pos.y);;

            gameObject.transform.position = newPos;
            gameObject.SetActive(true);
            //We add it to the element on screen

            //We want the right bound, not the center, that's why we don't divide by 2
            if (direction == BackGroundInsertionDirection.Right)
            {
                rightBound = pos.x + (width * directionFactor);
            }
            else
            {
                rightBound = pos.x;
            }
        }
        public void DisplayAtPosition(Vector3 pos,BackGroundInsertionDirection direction)
        {
            //We are placing the obect based on his center so we /2.0f the width

            int directionFactor;
            if(direction == BackGroundInsertionDirection.Right){
                directionFactor = 1 ;
            }else{
                directionFactor = -1;
            }
            Vector3 newPos = new Vector3(pos.x+((width/2.0f)*directionFactor),pos.y);;
            gameObject.transform.position = newPos;
            gameObject.SetActive(true);
            //We add it to the element on screen

            //We want the right bound, not the center, that's why we don't divide by 2
            if(direction == BackGroundInsertionDirection.Right){
                rightBound = pos.x+(width*directionFactor);
            }else{
                rightBound = pos.x;
            }
        }
        //Display a Random Prefab and position it at initialPosition return the x coordinate for the right bound
        private BackGroundElement DisplayRandomPrefab(Vector3 initialPosition,BackGroundInsertionDirection direction)
        {
            int randomIndex = 0;
            if(prefabsPool.Count==0){
                Debug.LogError("You need at least one prefab in the elements list.");
            }else if(prefabsPool.Count>1){
                randomIndex = Mathf.Abs(Random.Range(0,prefabsPool.Count));
            }

            //The element that will be rendered
            BackGroundElement renderedObject = prefabsPool[randomIndex].GetAvailableObject();

            renderedObject.DisplayAtPosition(initialPosition,direction);

            if(direction == BackGroundInsertionDirection.Right){
                elementsOnScreen.Add(renderedObject);
            }else{
                elementsOnScreen.Insert(0,renderedObject);
            }

            return renderedObject;
        }