Unity在代码中apply prefab

Unity在代码中apply prefab

两种方法:
1.替换asserts中的文件:
参考
https://blog.csdn.net/qq_36565626/article/details/83090171

https://blog.csdn.net/sinat_36373961/article/details/73252098

2.在代码中引用这个prefab,然后修改这个prefab的相关组件的参数。
比如
在这里插入图片描述
我在这个prefab上挂了个“WeaponRifle”脚本,里面有个属性叫damage,我就可以直接改prefab的damage:

weapons[0].GetComponent<WeaponRifle>().damage *= 1.1f;

猜你喜欢

转载自blog.csdn.net/realfancy/article/details/85051032
今日推荐