Created
December 2, 2021 01:34
-
-
Save kazukitanaka0611/2455dd869e9792aa4ab60882a2128b37 to your computer and use it in GitHub Desktop.
3角形から8角形までを生成する最低限のコード
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[RequireComponent(typeof(LineRenderer))] | |
public class Test : MonoBehaviour | |
{ | |
[SerializeField] | |
[Range(0, 5)] | |
private int _index = 0; | |
private static readonly int[] PointsNumbers = { 3, 4, 5, 6, 7, 8 }; | |
private LineRenderer _lineRenderer = null; | |
private void Awake() | |
{ | |
CreateLine(); | |
} | |
private void CreateLine() | |
{ | |
int initiatorPointsAmount = PointsNumbers[_index]; | |
Vector3 rotateVector = new Vector3(1.0f, 0.0f, 0.0f); | |
Vector3[] sourcePositions = new Vector3[initiatorPointsAmount + 1]; | |
for (var i = 0; i < initiatorPointsAmount; i++) | |
{ | |
sourcePositions[i] = rotateVector; | |
rotateVector = Quaternion.AngleAxis(360.0f / initiatorPointsAmount, new Vector3(0.0f, 0.0f, 1.0f)) * rotateVector; | |
} | |
sourcePositions[initiatorPointsAmount] = sourcePositions[0]; | |
if (TryGetComponent<LineRenderer>(out _lineRenderer)) | |
{ | |
_lineRenderer.enabled = true; | |
_lineRenderer.useWorldSpace = false; | |
_lineRenderer.loop = true; | |
_lineRenderer.positionCount = sourcePositions.Length; | |
_lineRenderer.SetPositions(sourcePositions); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment