Search code examples
c#arraysunity-game-enginemeshvertices

Unity: Set position of GameObjects as mesh vertices


for an augmented reality project I want to project an scalable picture ontop of 4 tracked images which should be like a map. Therefore I want to grab the locations of the Images and put an empty on them. The positions from this 4 emptys are then taken into a method to instantiate a plane on runtime. With fixed vertices my code worked well. My problem is that I cant write the positions of the emptys in the mesh vertices Array.

The Array Points contains the GameObjects and the positions of these Objects are passed correctly


Solution

  • I could, however I managed to do it, solve the problem. Not the prettiest code, but it works :)

    Mesh m = new Mesh();
            m.vertices = new Vector3[]
            {
                new Vector3(Points[0].transform.position.x, Points[0].transform.position.y, Points[0].transform.position.z),
                new Vector3(Points[1].transform.position.x, Points[1].transform.position.y, Points[1].transform.position.z),
                new Vector3(Points[2].transform.position.x, Points[2].transform.position.y, Points[2].transform.position.z),
                new Vector3(Points[3].transform.position.x, Points[3].transform.position.y, Points[3].transform.position.z),
            };