TrailRendererWith2DCollider

Author: Mike Hart (noodle!)

Description
I have searched in vain for a trail renderer that can detect collisions, so I decided to create one myself! There are definitely things that could be better optimized in this script, but it works just fine in the game I am working on. This trail renderer is meant to be used in the XY plane only, and it only works with 2D collisions. If used outside the XY plane, 2D polygon collider will not match up with the trail. Other than this, the trail behaves similarly to Unity's built-in TrailRenderer.

Usage
Attach this script to any moving object and a trail should be created behind it. Here is what all the public variables do:


 * trailMaterial: sets the material of the trail before the trail is created. To change the material of the trail during runtime, call the public method "ChangeTrailMaterial(Material)"
 * lifeTime: the length of the trail in seconds
 * changeTime: the time point during the trail's lifetime when the width begins to change. This should range from [0, lifeTime]
 * widthStart: the starting width of the trail
 * widthEnd: the ending width of the trail
 * vertexDistanceMin: the minimum distance between vertices
 * renderDirection: the direction that the trail faces towards. This should be a normalized vector
 * colliderIsTrigger: determines if the 2D polygon collider is a trigger before the trail is created. To change if the collider is a trigger during runtime, call the public method "ChangeColliderTrigger(bool)"
 * colliderIsEnabled: determines if the 2D polygon collider is enabled before the trail is created. To change if the collider is enabled during runtime, call the public method "ChangeColliderEnabled(bool)"
 * pausing: determines if the trail is pausing, i.e. neither creating nor destroying vertices

Here is what the public methods do:
 * ChangeTrailMaterial(Material): Changes the material of the trail during runtime
 * ChangeColliderTrigger(bool): Changes if the collider is a trigger or not during runtime
 * ChangeColliderEnabled(bool): Changes if the collider is enabled or not during runtime