-
카테고리
-
세부 분야
게임 프로그래밍
-
해결 여부
미해결
CS0103 오류가 생겼습니다
21.11.06 17:28 작성 조회수 350
0
안녕하세요. 강의를 따라하던 중 UI_Button.cs에서 Bind함수의 for문 안에 Util을 넣는 순간(?) 유니티에서 아래와 같은 오류가 떴습니다. 강의를 다시 보며 확인해봤지만 어느부분에서 틀린건지 찾지 못해서 도움을 요청합니다...ㅜㅠ
UI_Button.cs 코드입니다
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UI_Button : MonoBehaviour
{
Dictionary<Type, UnityEngine.Object[]> _objects = new Dictionary<Type, UnityEngine.Object[]>();
enum Buttons
{
PointButton
}
enum Texts
{
PointText,
ScoreText
}
private void Start()
{
Bind<Button>(typeof(Buttons));
Bind<Text>(typeof(Texts));
}
void Bind<T>(Type type) where T : UnityEngine.Object
{
string[] names = Enum.GetNames(type);
UnityEngine.Object[] objects = new UnityEngine.Object[names.Length];
_objects.Add(typeof(T), objects);
for (int i = 0; i < names.Length; i++)
{
objects[i] = Util.FindChild<T>(gameObject, names[i], true);
}
}
int _score = 0;
public void OnButtonClicked()
{
_score++;
}
}
Util.cs 코드 입니다
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Util
{
public static T FindChild<T>(GameObject go, string name = null, bool recursive = false) where T : UnityEngine.Object
{
if (go == null)
return null;
if(recursive == false)
{
for (int i = 0; i < go.transform.childCount; i++)
{
Transform transform = go.transform.GetChild(i);
if (string.IsNullOrEmpty(name) || transform.name == name)
{
T component = transform.GetComponent<T>();
if (component != null)
return component;
}
}
}
else
{
foreach(T component in go.GetComponentsInChildren<T>())
{
if (string.IsNullOrEmpty(name) || component.name == name)
return component;
}
}
return null;
}
}
답변을 작성해보세요.
0
Rookiss
지식공유자2021.11.07
위 내용만으로는 저도 알 수가 없네요.
해결이 안 된다면 전체 프로젝트 압축후 rookiss@naver.com로 보내주시면
제 환경에서도 문제가 재현되는지 확인해보겠습니다.
답변 1