예제 #1
0
    IEnumerator CutRope()
    {
        GameObject newRope = Mesh_Cutter.Cut(this.gameObject, transform.position, transform.right, null, true, false);

        if (newRope && newRope.GetComponent <MeshFilter>().sharedMesh.vertexCount > 0
            )
        {
            Destroy(this.transform.GetComponent <Collider>());
            CapsuleCollider collider = gameObject.AddComponent <CapsuleCollider>();
            Rigidbody       rigibody = newRope.AddComponent <Rigidbody>();

            GameObject rope = new GameObject("rope");
            rope.transform.position  = this.transform.position;
            rope.transform.parent    = ropeModel.transform.parent;
            newRope.transform.parent = rope.transform;

            CollisionScript col = newRope.AddComponent <CollisionScript>();
            col.ropeModel = rope;

            if (transform.childCount > 0)
            {
                Transform child = this.transform.GetChild(0);
                newRope.AddComponent <CapsuleCollider>();
                child.GetComponent <CharacterJoint>().connectedBody = rigibody;
                child.parent = newRope.transform;
            }

            AddChildren(rope.transform, rope);
        }
        StopCutting();
        Destroy(newRope, 0.5f);
        yield return(new WaitForSeconds(0f));
    }
예제 #2
0
    void OnCollisionEnter(Collision collision)
    {
        GameObject victim = collision.collider.gameObject;

        if (victim.tag == cuttableTag)
        {
            Material material = collision.collider.GetComponent <SkinnedMeshRenderer>() ?
                                collision.collider.GetComponent <SkinnedMeshRenderer>().sharedMaterials[0] :
                                collision.collider.GetComponent <MeshRenderer>().sharedMaterials[0];

            this.cutMaterial = this.cutMaterial != null ? this.cutMaterial : material;
            Mesh_Cutter.Cut(victim, transform.position, transform.right, this.cutMaterial, fill, addRigibody);
            StopCutting();
        }
    }