Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class ChangeMesh : MonoBehaviour {
- //The source object that we will be copying
- //vertex data from
- public GameObject goSource;
- void Start() {
- //Get the mesh of the source object
- Mesh meshObjectsMesh = (Mesh)(goSource.GetComponent().mesh);
- //Create a new mesh that we will assign to this object
- Mesh mesh = new Mesh();
- //Get the vertices from the source object and assign
- //them to the new mesh.
- mesh.vertices = meshObjectsMesh.vertices;
- //Get the uv map from the source object and assign
- //it to the new mesh.
- mesh.uv = meshObjectsMesh.uv;
- //Get the triangles from the source object and assign
- //them to the new mesh.
- mesh.triangles = meshObjectsMesh.triangles;
- //We can ask the engine to recalculate the normals
- //of the mesh, the normals are the surfaces that are rendered.
- mesh.RecalculateNormals();
- //We have to call RecalculateBounds to make sure
- //that the triangles from the vertex relationships
- //are recalculated correctly
- mesh.RecalculateBounds();
- //set the new mesh as the mesh for this object
- GetComponent().mesh = mesh;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement