- Home /
 
 
               Question by 
               simonellis1979 · Jun 20, 2018 at 06:55 PM · 
                2d gamevector3movement scriptvector2object pool  
              
 
              Movement on prefab objects
Hi all, could anyone help me I have a 2d game endless runner I have added a movement script to my prefab but if it spawns from my pool script the object only goes down and not back up. If I place my prefab into the scene the script works fine. What am I doing wrong here is the script I'm using for movement.
 Vector3 current_position;
 float direction = -1.0f;
 float speed = 1f;
 float heightlimit = 2f;
 float timecount = 0.1f;
 float timelimit = 0.1f;
 void Start(){
     current_position = this.transform.position;
 }
 void Update () 
 {
     transform.Translate (0, direction*speed*Time.deltaTime * 1, 0);
     if (transform.position.y >current_position.y+heightlimit) {
         direction = -1;
     }
     if (transform.position.y <current_position.y){
         direction = 1;
         timecount = timecount + Time.deltaTime;
         if (timecount > timelimit) {
             direction = 1;
             timecount = 0;
         }
     }
 }
 
               }
               Comment
              
 
               
              Your answer