09-02-2021, 11:53 PM
So, this is probably the easiest thing ever, but I can't seem to figure it out.
I'm trying to make some code that'll connect 2 objects together with a noodle, like in all the node editors.
Here's my code so far:
This works, and I can see the splines appear in the editor.
I can't figure out how to take my new spline and build a mesh around it with code.
I know how to add the mesh in the editor, but I need this to be pure code that updates and changes constantly during runtime.
My question is:
What code do I need to add to this to give it a mesh?
I'm trying to make some code that'll connect 2 objects together with a noodle, like in all the node editors.
Here's my code so far:
Code:
using UnityEngine;
using FluffyUnderware.Curvy;
namespace Connections {
public class Connection : MonoBehaviour {
private CurvySpline myspline;
public void SetPosition(Vector2 start, Vector2 end) {
if (!myspline) myspline = CurvySpline.Create();
myspline.Clear();
myspline.Add(
start,
new Vector3(start.x + ((end.x - start.x) * (float)0.2), start.y, 0),
new Vector3(end.x + ((start.x - end.x) * (float)0.2), end.y, 0),
end);
myspline.Refresh();
}
}
}
This works, and I can see the splines appear in the editor.
I can't figure out how to take my new spline and build a mesh around it with code.
I know how to add the mesh in the editor, but I need this to be pure code that updates and changes constantly during runtime.
My question is:
What code do I need to add to this to give it a mesh?