Mesh

Hello i have started learning how to use the Mesh class in unity3d but i can’t get the code in the documentation to run.

I got a error about sharedMesh

Here are my code:

using UnityEngine;
using System.Collections;

[RequireComponent(typeof(MeshFilter))]
[RequireComponent(typeof(MeshRenderer))]
public class example : MonoBehaviour {
    void Start() {
        Component[] meshFilters = GetComponentsInChildren<MeshFilter>();
        CombineInstance[] combine = new CombineInstance[meshFilters.Length];
        
		int i = 0;
        
		while (i < meshFilters.Length) {
            combine[i].mesh = meshFilters[i].sharedMesh;
            combine[i].transform = meshFilters[i].transform.localToWorldMatrix;
            meshFilters[i].gameObject.active = false;
            i++;
        }
		
        transform.GetComponent<MeshFilter>().mesh = new Mesh();
        transform.GetComponent<MeshFilter>().mesh.CombineMeshes(combine);
        transform.gameObject.active = true;
    }
}

Here are the error

Assets/example.cs(14,46): error CS1061: Type `UnityEngine.Component' does not contain a definition for `sharedMesh' and no extension method `sharedMesh' of type `UnityEngine.Component' could be found (are you missing a using directive or an assembly reference?)

Posting the error code will help.

Have added the error to my first post

MeshFilter[] meshFilters = GetComponentsInChildren<MeshFilter>();

Thank you. Now it works