A simple script that extrudes a mesh along a Spline in Unity
For a deeper explanation of how this script works, see my Medium Article.
You can simply download the two .cs
files into your Unity Project.
The included scripts use Unity's new Splines
package (UnityEngine.Splines
).
To extrude a mesh along a spline, follow these steps:
- Create a template mesh that the extruded mesh will be based on. A template mesh must be a 2D shape extruded along one axis (only tested using Z axis!). More info.
- Attach the
SplineMeshExtrude
script to a gameobject that also contains a Spline. - Set your template mesh under the
extrusion template mesh
field. - Select the extrusion axis of your template mesh under the
extrusion axis
field. (only tested using Z axis) - If you want the mesh to have smooth shading, check the
smooth faces
box. For flat shading, uncheck the box. - If you want the mesh to only allow rotation about the world up (Y) axis, check the
use world up
box. To allow 'twisting' around the spline, uncheck the box.
Enjoy!