2 qq 26470013 qq_26470013 于 2016.03.25 14:32 提问

unity3d文本的问题,是绑定的原因吗?

25 gameObject.Find("wenzi").GetComponent(GUIText).text="射弹数:" + sdshu;

报错,NullReferenceException: Object reference not set to an instance of an object
sheji.Update () (at Assets/sheji.js:25)
到底哪错了,求大神指点

2个回答

herozhangbz
herozhangbz   2016.03.25 14:49

我把我的给你吧。你看看能不能解决


 #pragma strict
function Start () {

}
var speed  =5;
var Newobject: Transform;
var sds :int=0;
var xhs :int=0;

function Update () {
    var x=Input.GetAxis("Horizontal")*Time.deltaTime*speed;
    var z=Input.GetAxis("Vertical")*Time.deltaTime*speed;
    transform.Translate(x,0,z);
//print(x);
if(Input.GetButtonDown("Fire1")){
var n: Transform = Instantiate(Newobject,transform.position,transform.rotation);
var fwd :Vector3 =transform.TransformDirection(Vector3.forward);
n.GetComponent.<Rigidbody>().AddForce(fwd*2800);
sds++;
//GameObject.Find("zt").GetComponent(GUIText).text="射弹计数:"+sds;
GameObject.Find("Canvas/zt").GetComponent(UnityEngine.UI.Text).text="射弹计数:"+sds+"销毁数:"+xhs;

}
if(Input.GetKey(KeyCode.Q)){
transform.Rotate(0,-25*Time.deltaTime,0,Space.Self);
}
if(Input.GetKey(KeyCode.E)){
transform.Rotate(0,25*Time.deltaTime,0,Space.Self);
}
if(Input.GetKey(KeyCode.W)){
transform.Rotate(-25*Time.deltaTime,0,0,Space.Self);
}
if(Input.GetKey(KeyCode.S)){
transform.Rotate(25*Time.deltaTime,0,0,Space.Self);
}
if(Input.GetKey(KeyCode.Z)){
transform.Translate(0,5*Time.deltaTime,0);
}
if(Input.GetKey(KeyCode.X)){
transform.Translate(0,-5*Time.deltaTime,0);
}
}
qq_26470013
qq_26470013 谢了!!!!
一年多之前 回复
CSDNXIAON
CSDNXIAON   2016.03.30 14:20

unity3d 线程安全问题
----------------------同志你好,我是CSDN问答机器人小N,奉组织之命为你提供参考答案,编程尚未成功,同志仍需努力!

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!