私は最近、UnityでC#を使ってプログラミングを検討しました。私はこの厄介な問題に遭遇しましたが、私はそれをどのように修正するか考えていません。私が "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!");
}
}
}
}
NOTEそれがない印刷 "1"。もうコードを見る必要があるかどうか教えてください。
ありがとうございます。
'C#'と 'C'は全く異なる言語です。 – kaylum
@kaylumこれはC# – Nicster15
です。私はそれが 'C#'であることを知っています。しかし、もともとは、誰かが親切にあなたのために削除した 'C'タグを持っていました。 – kaylum