Example #1
0
    private void CreateColliders()
    {
        var first                 = _rail.EnumerateSegments().First();
        var currentCollider       = NewCollider(first);
        var currentColliderIsWall = first.IsWall();

        foreach (var segment in _rail.EnumerateSegments().Skip(1))
        {
            if (segment.IsWall() == currentColliderIsWall)
            {
                // add point to current collider
                currentCollider.points = currentCollider.points
                                         .Concat(Enumerable.Repeat(segment.To - (Vector2)transform.position, 1))
                                         .ToArray();
            }
            else
            {
                currentCollider       = NewCollider(segment);
                currentColliderIsWall = segment.IsWall();
            }
        }
    }