void Start()
    {
        //Create a mesh filter while also assigning it as a variable to get the mesh property
        MeshFilter meshFilter = gameObject.AddComponent <MeshFilter> ();

        //Create a mesh renderer so we can actually display the mesh
        gameObject.AddComponent <MeshRenderer> ();

        //Set the mesh object to be that of the mesh from the mesh filter
        mesh = meshFilter.mesh;

        //Set a random material
        Object[] loadedMaterials = Resources.LoadAll("Materials");
        gameObject.GetComponent <Renderer> ().material = (Material)loadedMaterials [Random.Range(0, loadedMaterials.Length - 2)];

        windscreen = FindObjectOfType <Classic5Windscreen> ();
        CreateMesh();
    }
Beispiel #2
0
    void CreateClassicWindow()
    {
        //Get the classic car model windscreen script
        Classic5Windscreen classicWindscreen = GameObject.Find("Classic5Windscreen").GetComponent <Classic5Windscreen> ();

        //Assign the mesh vertices
        mesh.vertices = new Vector3[] {
            classicWindscreen.mesh.vertices [2],
            classicWindscreen.mesh.vertices [3],
            classicWindscreen.mesh.vertices [7],
            classicWindscreen.mesh.vertices [5]
        };

        //Assign the mesh triangles
        mesh.triangles = new int[] { 0, 2, 1, 2, 3, 1 };

        //Calculate the normals of the mesh fom the triangles
        mesh.RecalculateNormals();
    }