public static RopeCastingSegment NewEndSeg(RopeCasting mother, Vector2 start, Collider2D col) { // TODO make it an enum instead of this? This is not functional though :S var gObj = new GameObject("RopeSegmentEnd"); gObj.transform.parent = mother.transform; gObj.layer = 12; var nxt = gObj.AddComponent<RopeCastingSegment>(); nxt.mother = mother; nxt.bendsCross = 0; // This value should never be used on ends nxt.col = col; nxt.startOffset = nxt.col.transform.InverseTransformPoint(start); nxt.isEnd = true; return nxt; }
public static RopeCastingSegment NewSeg(RopeCasting mother, Vector2 start, RopeCastingSegment end, Collider2D col, float bendsCross) { var gObj = new GameObject("RopeSegment"); gObj.transform.parent = mother.transform; gObj.layer = 12; var nxt = gObj.AddComponent<RopeCastingSegment>(); nxt.mother = mother; nxt.end = end; nxt.col = col; nxt.startOffset = nxt.col.transform.InverseTransformPoint(start); nxt.bendsCross = bendsCross; nxt.eCol = gObj.AddComponent<EdgeCollider2D>(); nxt.eCol.isTrigger = true; nxt.IgnoreCollisions (); nxt.isEnd = false; // TODO Hacked to always add rigidbody so that it will detect when moving platforms hits it. // TODO RopeCast instead when you break instead? !?!?!? its not actualy because of moving platforms!!! if (col == null || end.isEnd || true) { // in this case this is the first or second to last segment // TODO add a seperate signifier for col == null var rig = gObj.AddComponent<Rigidbody2D> (); rig.gravityScale = 0; // TODO fix this hack to make it collide ? (it will not detect collision if there is no non kinematic rigidbodies involved). rig.collisionDetectionMode = CollisionDetectionMode2D.Continuous; } // Add Linerenderer var lr = gObj.AddComponent<LineRenderer> (); lr.SetVertexCount (2); lr.SetWidth (mother.ropeWidth, mother.ropeWidth); lr.material = mother.ropeMaterial; nxt.lr = lr; nxt.UpdateECol(); return nxt; }