예제 #1
0
    /* *************
     * CREATION
     * ===============*/

    private logic_rope_node createStartNode(GameObject originalNode, RigidbodyType2D bodyType)
    {
        // CREATE A TEMP NODE
        int index = this._ropeNodes.Count;

        GameObject temp = new GameObject();

        temp.name             = "rope_node_START_" + index;
        temp.transform.parent = this.gameObject.transform;
        temp.tag = "particle_object";

        Vector3 pos = originalNode.transform.position;

        temp.transform.position = new Vector3(pos.x, pos.y, this.transform.position.z); // Fix Z
        temp.layer = 13;

        Rigidbody2D tempBody = temp.AddComponent <Rigidbody2D>();

        tempBody.bodyType    = bodyType;
        tempBody.mass        = 100f;
        tempBody.angularDrag = 1f;

        logic_rope_node node = temp.AddComponent <logic_rope_node>();

        node.setRopeController(this);
        node.body = tempBody;

        return(node);
    }
예제 #2
0
    private logic_rope_node createRopeNode(logic_rope_node prevNode, Vector3 nodePos)
    {
        int index = this._ropeNodes.Count;

        // Main
        GameObject node = new GameObject();

        node.name               = "rope_node_" + index;
        node.transform.parent   = this.gameObject.transform;
        node.transform.position = new Vector3(nodePos.x, nodePos.y, this.transform.position.z); // Fix Z
        node.layer              = 13;
        node.tag = "particle_object";

        Rigidbody2D body = node.AddComponent <Rigidbody2D>();

        body.bodyType    = RigidbodyType2D.Kinematic;
        body.mass        = 100f;
        body.angularDrag = 1f;

        HingeJoint2D joint = this.createJoint(prevNode.body, node);

        LineRenderer lineRender = node.AddComponent <LineRenderer>();

        lineRender.receiveShadows       = false;
        lineRender.shadowCastingMode    = ShadowCastingMode.Off;
        lineRender.lightProbeUsage      = LightProbeUsage.Off;
        lineRender.reflectionProbeUsage = ReflectionProbeUsage.Off;
        lineRender.useWorldSpace        = false;
        lineRender.textureMode          = LineTextureMode.Tile;
        lineRender.sortingLayerName     = "Background";
        lineRender.sharedMaterial       = ropeMaterial;

        lineRender.positionCount = 2;
        lineRender.SetPosition(0, joint.anchor);
        lineRender.SetPosition(1, joint.connectedAnchor);

        lineRender.widthMultiplier = this.ropeWidth;

        EdgeCollider2D col = node.AddComponent <EdgeCollider2D>();

        col.isTrigger  = true;
        col.points     = new Vector2[] { joint.anchor, joint.connectedAnchor };
        col.edgeRadius = 0.03f;

        logic_rope_node logic_node = node.AddComponent <logic_rope_node>();

        logic_node.setRopeController(this);

        logic_node.col   = col;
        logic_node.line  = lineRender;
        logic_node.body  = body;
        logic_node.joint = joint;

        return(logic_node);
    }