Hi. I'm trying to find center of the selected gameobject (at runtime) that contains multiple childs (meshes). The functionality is similar to one that you can see in Unity Editor with transform's position gizmo.
The problem is that all object are displaced from null point (red ball in pictures). Tried using mesh.bounds, with max and min values, but still no luck.
Basically, I want to get red ball at position where the gizmo is.
Ok. Looks like I have solved this by myself. This code have no error checks but should be OK to get the idea :)
Vector3 getCenter(params MeshFilter meshes)
List<CombineInstance> combine = new List<CombineInstance>();
foreach (MeshFilter filter in meshes)
CombineInstance temp = new CombineInstance();
temp.mesh = filter.sharedMesh;
temp.transform = filter.transform.localToWorldMatrix;
Mesh combinedMesh = new Mesh();
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
3 People are following this question.
Set anchor point for procedural mesh?
Move from center and not pivot.
Creating a 3D Plane Mesh Without a Filled Center
Find center between 4 points
Find centres of the sides of a Hexagonal Mesh in UnityScript? Possible?