Hello!
I am currently working on a project that utilizes the SpriteShapeController component to create procedurally generated terrain. I am using Unity 2022.3.19f1.
I’ve been trying to find a way to randomly assign the SpriteShape edge sprite via code. I noticed that if I manually create points in my scene, I can assign sprite variants via the editor, as seen below -
However, I haven’t been successful in finding a way to do this through code. I found SpriteShapeMetaData.cs, which felt promising, but there doesn’t seem to be a way to access and assign individual points during or after their creation.
Below is a code snippet from my terrain generation code.
//shape = My SpriteShape
SpriteShapeMetaData _ssMD = shape.GetComponent<SpriteShapeMetaData>();
for (int i = 0; i < pointCount; i++){
shape.spline.SetTangentMode(i+2,ShapeTangentMode.Continuous);
//Current attempt to assign the spriteIndex variable with a random range (0-5) (sourced from the SpriteShape)
//Doesn't address the issue of assigning the spriteIndex for every point, though
_ssMD.spriteIndex = (uint) UnityEngine.Random.Range(0, 5);
shape.spline.SetLeftTangent(i+2,new Vector3(-2,0,0));
shape.spline.SetRightTangent(i+2,new Vector3(2,0,0));
}
If anyone has any tips or ideas on how to achieve this, I’d greatly appreciate it. Thank you!
