例如:
Create是某个脚本类(即public class 某某某 : MonoBehaviour)中的方法,该方法要在必然事件Update中调用(这个前提不能改变)。
bulletType是GameObject的实例,该变量对应的prefab有脚本BulletForward
脚本BulletForward的脚本类有属性velocity。
private void Create(float velovity=0){
GameObject newBullet = Instantiate (bulletType, this.transform.position, this.transform.rotation) as GameObject;
BulletForward bulletForward=newBullet.GetComponent<BulletForward>();
bulletForward.velocity = velovity;
}
```
上面的脚本在Update中调用方法了GetComponent。
听说方法GetComponent比较费时,不建议在Update()中调用。请问我听说的对吗?如果对,我应该如何重写方法Create,在设置GameObject的实例所挂载的脚本的参数velocity的同时避免上述缺陷?