스캔할때처럼 캐릭터 중앙에서부터 원을 그려서 캐릭터 반경 5m 주변까지 원이 점차 커져나가는 것을 구현
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Scan : MonoBehaviour
{
public LineRenderer lineRenderer;
public float radius = 0f; // Initial radius
public int segments = 360; // Number of segments to draw the circle
public float expandRate = 1f; // Expansion rate per second
public float maxRadius = 5f; // Maximum radius
public Transform characterTransform; // Reference to the character's transform
void Start()
{
lineRenderer = GetComponent<LineRenderer>();
StartCoroutine(DrawCircleRoutine());
}
void Update()
{
// 빈 오브젝트의 위치를 캐릭터의 위치로 업데이트
if (characterTransform != null)
{
transform.position = characterTransform.position;
}
}
IEnumerator DrawCircleRoutine()
{
while (true) // Infinite loop
{
radius += expandRate * Time.deltaTime; // Expand the radius every frame
if (radius > maxRadius)
{
radius = 0f; // Reset the radius to 0 if it exceeds the maximum
}
DrawCircleWithRadius(radius);
yield return null; // Wait until the next frame
}
}
void DrawCircleWithRadius(float radius)
{
lineRenderer.positionCount = segments + 1;
lineRenderer.startColor = Color.red;
lineRenderer.endColor = Color.red;
float x;
float y = transform.position.y; // Use the y position of the object
float z;
float angle = 20f;
for (int i = 0; i < (segments + 1); i++)
{
x = Mathf.Sin(Mathf.Deg2Rad * angle) * radius + transform.position.x; // Add the object's x position
z = Mathf.Cos(Mathf.Deg2Rad * angle) * radius + transform.position.z; // Add the object's z position
lineRenderer.SetPosition(i, new Vector3(x, y, z));
angle += (360f / segments);
}
}
}
캐릭터 오브젝트 자식에 빈 오브젝트를 만들고 거기에 스크립트를 넣어줌
그뒤 라인렌더러와 캐릭터 트랜스폼에 각각 오브젝트를 넣어주면 됨.
인벤토리, 장비 (1) | 2024.06.02 |
---|---|
애니메이터 아바타 변경하기(Animator.Avatar, 캐릭터 교체) (1) | 2024.05.01 |
19장. 좀비 서바이벌 멀티 플레이어( 네트워크 게임 월드 구현 ) (1) | 2024.05.01 |
18장. 좀비 서바이벌(멀티플레이) (0) | 2024.04.29 |
17장. 좀비 서바이벌(아이템 생성, 포스트 프로세싱) (0) | 2024.04.22 |