반응형
- 코드 작성
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FollowLine : MonoBehaviour
{
public Transform[] Points;
public IEnumerator<Transform> GetPathEnumerator()
{
if (Points == null || Points.Length < 1)
yield break;
var direction = 1;
var index = 0;
while (true)
{
yield return Points[index];
if (index <= 0)
direction = 1;
else if (index >= Points.Length - 1)
direction = -1;
index = index + direction;
}
}
public void OnDrawGizmos()
{
if (Points == null || Points.Length < 2)
return;
for (var i = 1; i < Points.Length; i++)
{
Gizmos.DrawLine(Points[i - 1].position, Points[i].position);
}
}
}
반응형
'개발 > C#' 카테고리의 다른 글
유니티 C# 플레이어 Hp바 간단 구현하기 (0) | 2023.01.29 |
---|---|
유니티 C# 물리 AddForce 간단 사용법 (0) | 2022.12.22 |
유니티 C# 일정거리 범위 안에 목표물 체크 Vector3.Distance (0) | 2022.12.22 |
유니티 C# UI 효과 깜빡이기 간단 구현 SpriteRenderer (0) | 2022.12.22 |
유니티 C# 카메라 이동범위 제한 Camera Mathf.Clamp (0) | 2022.12.22 |
유니티 C# 캐릭터 3인칭 카메라 따라가기 Follow Camera (0) | 2022.12.22 |
유니티 C# 카메라 목표지점까지 부드럽게 이동 Camera Vector3.SmoothDamp (0) | 2022.12.22 |
유니티 C# 텍스트 코드로 색깔 간단 변경법 Text Color (0) | 2022.12.22 |
댓글