250319 TIL

박소희·2025년 3월 19일

Unity_7기

목록 보기
50/94

Unity 배치고사

  1. Ray를 화면 중앙 기준으로 반환
Ray ray;
ray = camera.ScreenPointToRay(new Vector2(Screen.width/2, Screen.height/2));
// 카메라 화면 상 해당 지점의 실제 좌표, 카메라가 바라보고 있는 정면 방향 반환
  1. Coroutine 동작
using System.Collections;
using UnityEngine;

public class CoroutineTest : MonoBehaviour
{
    private Coroutine myCoroutine;
    private void Start()
    {
        StartTestCoroutine();
        Invoke("StartTestCoroutine", 1);
    }

    void StartTestCoroutine()
    {
        if (myCoroutine != null) StopCoroutine(myCoroutine);
        myCoroutine = StartCoroutine(TestCoroutine());
    }
    IEnumerator TestCoroutine()
    {
        Debug.Log("a");
        yield return null;
        Debug.Log("b");
        yield return new WaitForSeconds(3);
        Debug.Log("c");
    }
}

a > b > a > b > c

  • 3초 대기동안 StartTestCoroutine이 다시 호출돼서 기존 코루틴이 종료된다.

0개의 댓글