我是unity 3d的新手,我必须在退出项目中做一些增强。如果用户选择正确的选项,那么我必须在运行时在按钮周围显示一些粒子。我添加粒子的代码如下..不工作:
ParticleSystem ps = GetComponent<ParticleSystem>();
ps.Play ();
我还从统一编辑器中添加了粒子组件..
提前致谢
编辑 :
正如@kardux 建议的那样:
宣言 :
[SerializeField] private ParticleSystem ps;
关于方法:
ps.Play()
检查员截图:
错误:
I/Unity (23313): NullReferenceException
I/Unity (23313): at UnityEngine.ParticleSystem.<Play>m__0 (UnityEngine.ParticleSystem ps) [0x00001] in /Users/builduser/buildslave/unity/build/artifacts/generated/common/modules/ParticleSystem/ParticleSystemBindings.gen.cs:3666
I/Unity (23313): at UnityEngine.ParticleSystem.IterateParticleSystems (Boolean recurse, UnityEngine.IteratorDelegate func) [0x00003] in /Users/builduser/buildslave/unity/build/artifacts/generated/common/modules/ParticleSystem/ParticleSystemBindings.gen.cs:3780
I/Unity (23313): at UnityEngine.ParticleSystem.Play (Boolean withChildren) [0x00020] in /Users/builduser/buildslave/unity/build/artifacts/generated/common/modules/ParticleSystem/ParticleSystemBindings.gen.cs:3666
I/Unity (23313): at UnityEngine.ParticleSystem.Play () [0x00005] in /Users/builduser/buildslave/unity/build/artifacts/generated/common/modules/ParticleSystem/ParticleSystemBindings.gen.cs:3661