C#
[유니티] 오브젝트들을 거쳐가는 라인렌더러 생성
아스키의 공부방
2023. 8. 31. 20:41
728x90
반응형
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ObjectLine : MonoBehaviour
{
LineRenderer lineRenderer;
public Transform[] pathPoints; // 오브젝트들의 위치를 순서대로 저장하는 배열
private void Start()
{
lineRenderer = GetComponent<LineRenderer>();
DrawPath();
}
private void Update()
{
DrawPath(); // 포지션 고정일 시 제거
}
void DrawPath()
{
lineRenderer.positionCount = pathPoints.Length; // 라인 렌더러의 버텍스 수를 경로의 포인트 수로 설정
for (int i = 0; i < pathPoints.Length; i++)
{
lineRenderer.SetPosition(i, pathPoints[i].position); // 라인 렌더러의 각 버텍스 위치 설정
}
}
}
728x90
반응형