using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.SearchService;

public class coTest : MonoBehaviour
{
    void Start()
    {
        //StartCoroutine(this.Sol1());
        //StartCoroutine(this.Sol2());
    }

    void Update()
    {
       
    }

    //1. 주어진 시간(예: 5초) 동안 특정 작업을 반복 실행하고 그 후에 작업을 중지하는 코루틴을 작성하세요.
    //IEnumerator Sol1()
    //{
    //    Debug.LogFormat("시작"); // 처음에 0초 출력

    //    yield return new WaitForSeconds(1); // 1초 대기

    //    for (int i = 1; i <= 5; i++)
    //    {
    //        Debug.LogFormat("{0}초 경과", i);
    //        yield return new WaitForSeconds(1); // 각 반복마다 1초씩 대기
    //    }

    //    Debug.Log("정지");
    //}

    //2. 리스트에 있는 항목을 하나씩 출력하고 각 항목을 출력한 후에 잠시 대기하는 코루틴을 만들어보세요.
    //IEnumerator Sol2()
    //{
    //    string[] items = { "cap", "clothes", "pants", "shoes" };
    //        foreach (string item in items)
    //        {
    //            Debug.Log(item);
    //            yield return new WaitForSeconds(1);
    //        }
    //        Debug.Log("모든 아이템 출력 완료");
    //}

    //3.플레이어가 특정 키를 누를 때까지 게임을 일시 중지하고, 그 키를 누르면 다시 게임을 계속하는 코루틴을 작성하세요.
 

}

 

using System.Collections;
using UnityEngine;

public class GameLogic : MonoBehaviour
{
    private bool gamePaused = false;

    void Start()
    {
        StartCoroutine(GameLoop());
    }
    //3. 플레이어가 특정 키를 누를 때까지 게임을 일시 중지하고, 그 키를 누르면 다시 게임을 계속하는 코루틴을 작성하세요.
    IEnumerator GameLoop()
    {
        while (true)
        {
            if (!gamePaused)
            {
                // 게임이 진행 중인 경우 여기에 원하는 게임 로직을 추가
                Debug.Log("게임 진행 중");
            }

            // 플레이어가 스페이스바를 누르면 일시 중지 상태를 변경
            if (Input.GetKeyDown(KeyCode.Space))
            {
                gamePaused = !gamePaused;

                if (gamePaused)
                {
                    Debug.Log("게임 일시 중지");
                    Time.timeScale = 0f; // 게임 시간 정지
                }
                else
                {
                    Debug.Log("게임 재개");
                    Time.timeScale = 1f; // 게임 시간 재개
                }
            }

            yield return null;
        }
    }
}

'산대특 > 게임 클라이언트 프로그래밍' 카테고리의 다른 글

Quaternion  (1) 2024.03.04
Dodge game  (0) 2024.03.04
StarCraft - Tank  (0) 2024.02.29
StarCraft - DropShip Logic  (0) 2024.02.28
Find the nearest object  (0) 2024.02.27

+ Recent posts