Unity ParticleSystem collidesWith

问题描述 投票:1回答:1

我试图在脚本中改变粒子系统的collidesWith参数,但我得到了这个错误。

错误CS1612 不能修改 "ParticleSystem.collision "的返回值,因为它不是一个变量。

我的代码。

GameObject ammo; //Game object with ParticleSystem on it
public LayerMask desiredLayers; 

private void Start()
{
    ammo.GetComponent<ParticleSystem>().collision.collidesWith = desiredLayers;
}

现在我的问题是什么是改变粒子系统碰撞层的正确方法。

unity3d particle-system
1个回答
1
投票

好吧,我想明白了,显然ParticleSystem是一个属性。

Unity对ParticleSystem有一些特殊的功能,它使用指针,所以下面的代码解决了我的问题。

var collidesWith = ammo.GetComponent<ParticleSystem>().collision.collidesWith;
collidesWith = desiredLayers;
© www.soinside.com 2019 - 2024. All rights reserved.