Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to manually load an existing mesh

Discussion in 'Scripting' started by Andre Gregoire, Oct 19, 2009.

  1. Andre Gregoire

    Andre Gregoire

    Joined:
    Aug 28, 2009
    Posts:
    32
    Ok, my problem was when i was creating bullets the capsules,even if they were scripted a certain size, were created in there default value. So i decided to make an empty prefab and AddComponents by scripting. The only problem is i do not know how to load the capsule mesh? I know how to load from a resource file and i know i can go and choose another mesh. Regardless, i'm very curious on how to load a primitiveType mesh like a Capsule? (By scripting of course)

    Code (csharp):
    1. void Awake ()
    2.     {
    3.         obj_=this.gameObject;
    4.         tran_=obj_.transform;
    5.         obj_.AddComponent ("Rigidbody");
    6.         obj_.AddComponent("CapsuleCollider");
    7.         obj_.AddComponent ("MeshFilter");
    8.         mesh_=((MeshFilter) obj_.GetComponent("MeshFilter")).mesh;
    9. //mesh_=Capsule.mesh...or something like that?
    10.     }
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    primitive types are not loaded by generated by the corresponding class.
    if you search the script reference for cube or sphere you will surely find its name, don't know it out of head.