[개발일지] 나폴리탄스파게티 20230602

2023. 6. 9. 21:522학년 1학기 프로젝트

 


이벤트 매니저 구현

(미완성) 이벤트를 랜덤으로 진행하게 하고 총괄하는 스크립트 작성

진행할 이벤트가 기존에 이미 진행중이라면 재추첨 필요

 

public class EventManager : MonoBehaviour
{
    public GameObject CCTVeventController, paintEventController;
    
    public int nowEvent; // 현재 진행중인 이벤트 개수를 담을 변수
    public int typeEventNum; // 진행 확정된 이벤트 종류 정보를 담을 변수
    int randomEventNum; // 확정되지 않은 이벤트 종류를 랜덤으로 담을 변수

    int isEvent; // 이벤트를 진행할지 하지않을지 결정하는 값을 담을 변수
    int index;

    bool isThere; // 중복값 확인할 변수

    List<int> TypeEventList = new List<int>();

    public Text EventTypeText; // 현재 진행중인 이벤트 종류를 숫자로 나타낼 Text UI

    void Start()
    {
        
        RandomEvent();
    }
    
    void Update()

    // Event를 진행할지 랜덤하게 결정하는 메서드
    void RandomEvent()
    {
        isEvent = Random.Range(0, 2); // 0, 1 (0: 진행X / 1: 진행O)
        
        if(isEvent == 1)
        {
            Debug.Log("진행할 이벤트 종류 추첨");

            randomEventNum = Random.Range(1, 8); // 1~7번 이벤트 결정
            
            isThere = TypeEventList.Contains(randomEventNum);
            Debug.Log(isThere);

            // 기존에 진행중인 이벤트 중 중복된 값이 없을 때 진행
            if(isThere == false)
            {
                typeEventNum = randomEventNum; // 이벤트 진행 확정
                nowEvent++; // 현재 진행중인 이벤트 개수 추가
                TypeEventList.Add(typeEventNum); // 진행 이벤트 정보 저장
                EventTypeText.text = TypeEventList[0].ToString(); 
            }

            // List에 저장된 이벤트 종류가 몇번에 저장되어있는지 찾아주는 메서드
            {
                int index = TypeEventList.IndexOf(item);
            }

            // 진행중인 이벤트 Debug.Log
            foreach(int a in TypeEventList)
            {
                Debug.Log(index);
                Debug.Log(a);
            }
        }
        // 확인을 위한 Debug.Log (테스트 끝나면 지울 것)
        else
        {
            Debug.Log("이벤트 진행하지 않음");
        }

        if(nowEvent < 3)
        {
            Invoke("RandomEvent", 2);
        }
    }
}