Search Unity

Manually assigning a built-in mesh???

Discussion in 'Scripting' started by EnsurdFrndship, Feb 12, 2016.

  1. EnsurdFrndship

    EnsurdFrndship

    Joined:
    Apr 17, 2010
    Posts:
    786
    Hello,
    I know that using

    gameobject.GetComponent<MeshFilter> ().mesh = meshValue;

    is a good way to assign a mesh to the object, but how do I gain access to all the built-in meshes that Unity has (like Cube, Sphere, Cylinder, etc.)? I wish there was a UnityBuiltInShapes.Cube feature.
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
  3. bigmisterb

    bigmisterb

    Joined:
    Nov 6, 2010
    Posts:
    4,221
    Code (csharp):
    1.  
    2. var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
    3. var mesh = cube.GetComponent<MeshFilter>().mesh;
    4.  
     
  4. EnsurdFrndship

    EnsurdFrndship

    Joined:
    Apr 17, 2010
    Posts:
    786
    Thank you.