Question by 
               matrix_becker · Mar 28, 2016 at 01:53 PM · 
                prefabruntimeparallax  
              
 
              I have two Background Prefab. I want to generate and spawn them at Rutime in alternative ways..like Bg1..Bg2..Bg1..Bg2....thats way. Also in smooth manner. This will happen in canvas only... I will give my code following....Please suggest me...
using UnityEngine; using System.Collections;
public class BGScroller : MonoBehaviour {
 public float ScrollSpeed;
 public GameObject Background;
 public GameObject Background1;
 public Transform canvas;
 
 void Start()
 {
     Instantiate();
 }
 void Update()
   {
     Background.transform.Translate(Vector3.left * Time.deltaTime*ScrollSpeed);
     Background1.transform.Translate(Vector3.left * Time.deltaTime*ScrollSpeed);
 }
 void Instantiate()
 
               { Background= (GameObject)Instantiate (Resources.Load("Prefabs/Background",typeof(GameObject))); Background.transform.SetParent (canvas, false); Background1 = (GameObject)Instantiate (Resources.Load ("Prefabs/Background-1", typeof(GameObject))); Background1.transform.SetParent (canvas, false);
     StartCoroutine ("waitFor");
     Destroy (Background, 44f);
 }
     
 IEnumerator waitFor(){
     yield return new WaitForSeconds (44f);
     Instantiate();
 }
 
               }
               Comment
              
 
               
              Your answer
 
             Follow this Question
Related Questions
How to detect if any prefab is instantiated in the scene from a script? 2 Answers
Editing prefabs at runtime 0 Answers
Unity network manager assign playerprefab at runtime 0 Answers
Accidentally editing prefab values at runtime 1 Answer
Animate a Prefab and change Clip Properties programmatically 0 Answers