unity3d问题:“未将对象引用设置到对象的实例” 100
usingUnityEngine;usingSystem.Collections;publicclassshibingkongzhi:MonoBehaviour{publ...
using UnityEngine;
using System.Collections;
public class shibingkongzhi : MonoBehaviour {
public Texture2D[] shenti;
public Texture2D[] jiao;
public bool pd=false;
private shibingtuei tuei;
private shinbingshenti shen;
private Transform transtuei;
private Transform transshen;
private GameObject game;
public lei start;//引用enum类型
// Use this for initialization
void Start () {
transtuei=transform.FindChild("shibing");
transshen=transform.FindChild("jiao");
shen =transshen.GetComponent("shinbingshenti")as shinbingshenti;
tuei=transtuei.GetComponent("shibingtui")as shibingtuei;
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown(KeyCode.A)){
start=lei.leftwalk;
pd=true;
}
if(Input.GetKeyDown(KeyCode.D)){
start=lei.rightwalk;
pd=false;
}
switch(start){
case lei.leftwalk:
user(shenti,jiao,pd);
break;
case lei.rightwalk:
user(shenti,jiao,pd);
break;
default:
break;
}
}
void user(Texture2D[] a,Texture2D[] b,bool car){
shen.fame=a;//fame是tuextrue2D[]
tuei.fame=b;//fame是tuextrue2D[]
if(car){
shen.pd=true;
tuei.pd=true;
}else{
shen.pd=false;
tuei.pd=false;
}
return;
}
}
提示错误:
NullReferenceException: Object reference not set to an instance of an object
shibingkongzhi.user (UnityEngine.Texture2D[] a, UnityEngine.Texture2D[] b, Boolean car) (at Assets/Scripts/shibing/shibingkongzhi.cs:46)
shibingkongzhi.Update () (at Assets/Scripts/shibing/shibingkongzhi.cs:39)
我怀疑是user函数那声明有误,但不知道怎么改,求大神解答。 展开
using System.Collections;
public class shibingkongzhi : MonoBehaviour {
public Texture2D[] shenti;
public Texture2D[] jiao;
public bool pd=false;
private shibingtuei tuei;
private shinbingshenti shen;
private Transform transtuei;
private Transform transshen;
private GameObject game;
public lei start;//引用enum类型
// Use this for initialization
void Start () {
transtuei=transform.FindChild("shibing");
transshen=transform.FindChild("jiao");
shen =transshen.GetComponent("shinbingshenti")as shinbingshenti;
tuei=transtuei.GetComponent("shibingtui")as shibingtuei;
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown(KeyCode.A)){
start=lei.leftwalk;
pd=true;
}
if(Input.GetKeyDown(KeyCode.D)){
start=lei.rightwalk;
pd=false;
}
switch(start){
case lei.leftwalk:
user(shenti,jiao,pd);
break;
case lei.rightwalk:
user(shenti,jiao,pd);
break;
default:
break;
}
}
void user(Texture2D[] a,Texture2D[] b,bool car){
shen.fame=a;//fame是tuextrue2D[]
tuei.fame=b;//fame是tuextrue2D[]
if(car){
shen.pd=true;
tuei.pd=true;
}else{
shen.pd=false;
tuei.pd=false;
}
return;
}
}
提示错误:
NullReferenceException: Object reference not set to an instance of an object
shibingkongzhi.user (UnityEngine.Texture2D[] a, UnityEngine.Texture2D[] b, Boolean car) (at Assets/Scripts/shibing/shibingkongzhi.cs:46)
shibingkongzhi.Update () (at Assets/Scripts/shibing/shibingkongzhi.cs:39)
我怀疑是user函数那声明有误,但不知道怎么改,求大神解答。 展开
2个回答
展开全部
很有可能是某些值为空,你确定user函数中传入的参数都不为null?加个断点调试下吧。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询