최근에 C#을 사용하여 Unity에서 프로그래밍을 살펴보기로 결정했습니다. 나는이 불쾌한 문제에 부 닥쳤다. 나는 그것을 고치는 법을 모른다. 꽤 많이 "instanceGo.GetComponent"를 호출하면 null을 반환합니다. 나는 무엇을해야할지 모른다. 어떤 아이디어라도 도움이 될 것입니다!UNITY C# GetComponent Returns Null
CODE
// Update is called once per frame
void Update() {
if (Input.GetKey ("p")) {
printMessage = !printMessage;
}
if (instanceGo.GetComponent<SpawnZombiesHandler>() == null) {
print ("1");
} else {
print ("2");
}
foreach(GameObject bullet in instanceGo.GetComponent<ArcherBulletShootHandler>().getBullets()){
print ("12");
foreach (GameObject zombie in instanceGo.GetComponent<SpawnZombiesHandler>().getZombies()) {
hit (bullet, zombie);
if(Mathf.RoundToInt(zombie.transform.position.y) == Mathf.RoundToInt(bullet.transform.position.y) &&
Mathf.RoundToInt(zombie.transform.position.x) == Mathf.RoundToInt(bullet.transform.position.x)) {
print("HIT!");
}
}
}
}
참고 그것은합니까 인쇄 "1". 더 이상 코드가 필요한지 알려주십시오.
감사합니다.
'C#'과 'C'는 완전히 다른 언어입니다. – kaylum
@kaylum 이것은 C# – Nicster15
입니다. 나는 그것이'C#'임을 압니다. 하지만 원래는'C' 태그를 사용하여 누군가 당신을 위해 친절하게 제거했습니다. – kaylum