title: How to make my sprite object go offscreen to the left and have it appear on the right?
body: <p>In <code>Unity</code>, I'm trying to make my sprite go offscreen to the left and have it appear offscreen on the right or vice versa. I have my sprite move left or right (depending on user input) constantly for my gameplay by the way.</p>
  
  <p>I take into account that the sprite needs to be fully offscreen before having it appear on the right side.</p>
  
  <p>Here's my current code:</p>
  
  <pre><code>void Start () 
  {
      minXValueWorld = Camera.main.ScreenToWorldPoint(new Vector3(0,0,0)).x;
      maxXValueWorld = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, 0, 0)).x;
  
      playerSize = this.GetComponent&lt;Renderer&gt;().bounds.size;
  }
  
  void Move()
  {
      if (inputLeft)
      {
          this.transform.position -= new Vector3(speed * Time.deltaTime, 0, 0);
      }
      else
      {
          this.transform.position += new Vector3(speed * Time.deltaTime, 0, 0);
      }
  }
  
  void OffscreenCheck()
  {
  
      Vector3 screenPos = Camera.main.WorldToScreenPoint(this.transform.position);
      Vector3 maxWorldXWithPlayerSize = Camera.main.WorldToScreenPoint(new Vector3(maxXValueWorld,0,0) + playerSize/2);
      Vector3 minWorldWithPlayerSize = Camera.main.WorldToScreenPoint(new Vector3(minXValueWorld,0,0) - playerSize/2);
  
      if (screenPos.x &lt; minWorldWithPlayerSize.x)
      {
          this.transform.position = new Vector3(maxWorldXWithPlayerSize.x, this.transform.position.y, this.transform.position.z);
      }
  
      if (screenPos.x &gt; maxWorldXWithPlayerSize.x)
      {
          this.transform.position = new Vector3(minWorldWithPlayerSize.x, this.transform.position.y, this.transform.position.z);
      }
  
  }
  </code></pre>
  
  <p>Then the <code>Move</code> and <code>OffscreenCheck</code> are called in the <code>Update</code> function in order.</p>
  
  <p>The problem with this code is that once my sprite goes fully offscreen on the left, it appears on the right offscreen, but it does not move left anymore.</p>
  
  <p>Instead, it just teleports to the left or right offscreen positions. I do not see it move left or right across the screen anymore because of this.</p>
  
  <p>I'm pretty sure that my code logic is just off. Does anyone know how to fix this issue?</p>
  
  <p>Thanks</p>