Start 和 Awake 的区别

From 呼吸的草稿本

Jump to: navigation, search

GameObject obj = (GameObject) Instantiate(enemyNormal,normalGP[index].position ,Quaternion.identity);

CarMovementScript moveCon = (CarMovementScript)obj.GetComponent(typeof(CarMovementScript));

moveCon.MoveToTarget(count);


比如这行代码。

MoveToTarget 会使用到一个初始值,但是如果在 start 里面赋值后上面代码就会出错。那时候还没调用 Start方法

所以解决的方法就是把赋值的语句写在 Awake 里面

Personal tools