SebLague / Path-Creator

Path creation asset for Unity game development
https://assetstore.unity.com/packages/tools/utilities/b-zier-path-creator-136082
MIT License
1.83k stars 319 forks source link

Make 2d Collision #98

Closed Zaitam closed 3 years ago

Zaitam commented 3 years ago

Is there anyway to add a 2d box/edge collider that follows the path?

Zaitam commented 3 years ago

Fixed it by getting the Vertex Count and setting them to a list.

using System.Collections.Generic;
using UnityEngine;
using PathCreation;

public class pathCollider : MonoBehaviour
{
    [SerializeField]private EdgeCollider2D _edgeCollider2D;
    private List<Vector2> _list = new List<Vector2>();
    private PathCreator _path;
    private int _VertexCount;

    private void Start()
    {
        _VertexCount = _path.path.NumPoints;
        for (int i = 0; i < _VertexCount; i++)
        {
            _list.Add(_path.path.GetPoint(i));
        }

        _edgeCollider2D.SetPoints(_list);
    }
}