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)
到底哪错了,求大神指点
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)
到底哪错了,求大神指点
我把我的给你吧。你看看能不能解决
#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);
}
}