title: How do I center a mesh on a GameObject?
body: <p>I have a 2D game where the users can create cars by clicking on the screen to add vertices and then drag these around as they see fit. These vertices are then used to draw a mesh. Users can also add wheels to the vertices (1 per vertex).</p>
  
  <p>In the game there is also an option to have the computer generate a random car, which it does by creating eight vertices at random points inside of a <a href="http://docs.unity3d.com/ScriptReference/Random-insideUnitCircle.html" rel="nofollow noreferrer">unit circle</a>.</p>
  
  <p>These cars are stored and it is possible for the user to load them and re-use them. The two pictures below show a square button with a computer generated car (The green one with red wheels) which sits inside of the square as intended, and a user generated car (The white one with pink wheels) which sits outside of the square.</p>
  
  <p>I know that this is because the mesh of the computer generated one draws triangles from Vector3.zero which is the center of the object, while the user created one only triangles between the vertices, which aren't necessarily placed around the center of the object (As in this example where they are all placed above and to the right of the center).</p>
  
  <p><strong>How would I go about centering the mesh of the user created car?</strong></p>
  
  <p>I could perhaps calculate the center of the mesh and then subtract that from the position of all the vertices. Or I could subtract that position from the position of the GameObject that holds the mesh when presenting it in the gui. Or are there better alternative solutions?</p>
  
  <p><a href="https://i.stack.imgur.com/wBfyQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wBfyQ.png" alt="Object that sits inside of the square"></a>
  <a href="https://i.stack.imgur.com/IvRYG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IvRYG.png" alt="Object that does not sit inside of the square"></a></p>