我想通过代码处理粒子系统 . 如果父多维数据集的高度为10个单位,则粒子系统应自行计算startLifeTime(到达多维数据集的顶部) .
所以..我用的计算是
startLifetime = cubeHeight / startSpeed
现在的代码
private void Start()
{
Vector3 liftScale = transform.localScale; // The scaling of my object
ParticleSystem.ShapeModule particleShape = liftParticles.GetComponent<ParticleSystem>().shape; // reference to the shape
particleShape.radius = liftScale.x > liftScale.z ? liftScale.x : liftScale.z; // set the radius
ParticleSystem.MainModule particleMain = liftParticles.GetComponent<ParticleSystem>().main; // reference to the PS.main
particleMain.startLifetime = liftScale.y / particleMain.startSpeed; // set the startLifetime
}
编译时说,使用此代码时
运算符不能应用于'float'和'ParticleSystem.MinMaxCurve'类型的操作数
那么如何计算 liftScale.y / particleMain.startSpeed
?
2 回答
你需要使用
particleMain.startSpeed.constant
.这意味着particleMain.startSpeed具有MinMaxCurve类型 . 尝试通过particleMain.startSpeedMultiplier替换它 .