hey-new user needs quick c# help..almost got it..

I am trying to set some parameters in c# but must have some syntax wrong…any help would be great!!I
Look at my comments to see what I am trying to do…import large amounts of building fracture peices into unity , to set up a destructable low poly city…

I am trying to set
convex=true on MeshCollider
and the weight,drag, etc. on the Rigidbody

I have confirmed that I can create the the two components,
I just need to update those parameters.

    // Add a mesh collider/rigid body to each fracture peice
    void Apply(Transform transform)
    {
        if (transform.name.ToLower().Contains("fracture_chunk"))
        {
            transform.gameObject.AddComponent(typeof(MeshCollider));
            //set values I need!
            //transform.gameObject.GetComponent(typeof(MeshCollider));
            //<MeshCollider>.convex=true;

            transform.gameObject.AddComponent(typeof(Rigidbody));
            //transform.gameObject.GetComponent(typeof(RigigBody));
            //<RigidBody>.Mass=1.0;
            //<RigidBody>.Drag=.5
            //<RigidBody>.AngularDrag=.1
        }

        foreach (Transform child in transform)
            Apply(child);
    }

Thanks!!!

or how to change the default values of (newly created) unity components??

  • you are using the old style AddComponent. Still works but the new one is preferred.
  • you seem confused over what means, look up Generics in c#
    Here’s how to do it, for reference:
MeshCollider meshcol = gameObject.AddComponent<MeshCollider>();
meshcol.convex = true;

cool, thanks…, I know, T is a refernce to the actual transform of the attatched game obect…

had this idea this morning, and this is what I came up with…

forcevfx.com/unity3d/destructable/
there a hundred or so chunks, so that really helps!!

No, is a type specifying what type of object the Generic operates on. Check out some links, a rough knowledge of how they work is really useful in C#.
http://lmgtfy.com/?q=generics+in+c%23
(please note use of lmgtfy is not meant to be rude, it’s just a short link)

I’ m really trying…I’ll take some time to review…thanks again…
some smoke, detonator, soundFX, it may just work…