There may be a time when you need to create a modified object from scratch via code, if so the code snippet below shows you the basics of what you need to do. First make sure the object you are adding the modifiers to have a MeshFilter with a mesh in. Then you just need to use the AddComponent method to add the MegaModifyObject component to the gameobject, once that is done you can add any modifiers you like to the object you just need to remember to call MeshUpdated() at the end, you should call this method if you add any further modifiers at any time, this will tell the system to recalculate the internal tables and resort etc the existing Modifiers. Don’t forget you can reorder the modifiers by changing the Order int value and then calling MeshUpdated().
public class MakeModObject : MonoBehaviour
{
GameObject target;
MegaModifyObject modObj;
MegaBend bendMod;
float angle = 0.0f;
void Start()
{
if ( target )
{
modObj = target.AddComponent<MegaModifyObject>();
bendMod = target.AddComponent<MegaBend>();
modObj.MeshUpdated(); // Call this after all modifers have been added
}
}
void Update()
{
angle += Time.deltaTime;
bendMod.angle = angle;
}
}