Unity - A计划(永久有效期) 扫二维码继续学习 二维码时效为半小时

(196评价)
价格: 4019.00元
[黑黯之光 RPG]使用HUDText在小狼头上显示Miss效果,未显示出Miss效果,报空指针
xiaoli84512发起了问答2017-12-04
1
回复
562
浏览

 

报错

NullReferenceException: Object reference not set to an instance of an object
Enemy.Start () (at Assets/Scripts/Enemy/Enemy.cs:55)
 

代码

void Start(){
  //hudtextGo = GameObject.Instantiate (hudtextPrefab, Vector3.zero, Quaternion.identity) as GameObject;
  //hudtextGo.transform.parent = HUDTextParent._instance.gameObject.transform;
  hudtextGo = NGUITools.AddChild(HUDTextParent._instance.gameObject, hudtextPrefab);

  hudtext = hudtextGo.GetComponent<HUDText>();
  followTarget = hudtextGo.GetComponent<UIFollowTarget>();
  followTarget.target = hudtextFollow.transform;
  followTarget.gameCamera = Camera.main;
  print (UICamera.current);
  print (UICamera.currentCamera);
  followTarget.uiCamera = UICamera.current.GetComponent<Camera>();   //55行
 }

 

 

unity 4.6  ngui

所有回复
  • siki 2017-12-05

    首先应该不是followTarget的空,因为上面也使用了这个对象没什么问题

    所以应该是UICamera.current为空,这个检查下为什么空,或者换别的方式去得到Camera

    还有-5条回复,点击查看
    你还没有登录,请先登录注册
发表回复
你还没有登录,请先 登录或 注册!