Unity3D 작동하지 나는 다음과 같습니다 크로스바에 스크립트 추가 :점수 카운터는
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class crossbarscript : MonoBehaviour {
public AudioSource ping;
public static int score;
public Rigidbody rb;
public Text text;
// Use this for initialization
void Start() {
ping = GetComponent<AudioSource>();
rb = GetComponent<Rigidbody>();
score = 0;
}
// Update is called once per frame
public void OnCollisionEnter (Collision col) {
if(col.gameObject.name == "Ball")
{
text = GetComponent<Text>();
text.text = "Score: " + score; //This is the line the error is pointing at
ping.Play();
rb.freezeRotation = true;
}
}
}
그리고의를 콘솔, 내가 이것을 얻을 : NullreferenceException : 개체 참조가 개체의 인스턴스로 설정되지 않았습니다
내가 뭘하려고하는지 공이 크로스바 (스크립트가 첨부 된 개체를 때릴 때마다 그렇게되도록 만드는 것입니다) 왼쪽 위 모서리에있는 텍스트의 점수에 추가됩니다. 이 문제를 해결할 방법이 있는지 아니면 다른 방법으로해야하는지 알려주세요. 감사합니다.
[NullReferenceException이란 무엇이며 어떻게 수정합니까?] (http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix -it) –
해당 오류를 클릭하고 오류의 원인이되는 코드 행을 사용하여 질문을 편집하십시오. – Programmer
@Programmer 완료. –