get_transform is not allowed to be called from a MonoBehaviour constructor (or instance field initia

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/atgczcl/article/details/52396805

get_transform is not allowed to be called from a MonoBehaviour constructor (or instance field initializer), call it in Awake or Start instead.

这个问题的出现,千万不能出现,出现就说明你的代码质量不够高,stupidcode man!!! or girl…

第一种:

Error code:
private Transform mainCameraTr = Camera.main.transform;

Right Code:
private Transform mainCameraTr ;

void Start(){
    mainCameraTr = Camera.main.transform;
}

第二种:

public class RotateAroundSelf : MonoBehaviour {

     public RotateAroundSelf(float foo)  // Class class constructor
     {
         Vector3 speed = new Vector3(0,foo,0); //now it's evil
     }
 }

代码必须要规范的写;

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试