index | 分配力场的索引。 |
field | 要分配的力场。 |
在影响者列表中给定索引处分配力场。
当influenceFilter设置为ParticleSystemGameObjectFilter.List时,只有影响者列表中的力场会影响粒子系统。
using UnityEngine;
public class Example : MonoBehaviour { public ParticleSystem system; public ParticleSystemForceField field1; public ParticleSystemForceField field2;
ParticleSystem.ExternalForcesModule m_ExternalForcesModule;
void Start() { if (system == null) { Debug.LogError("Please assign a Particle System to `system`."); enabled = false; return; }
if (field1 == null || field2 == null) { Debug.LogError("Please assign a ParticleSystemForceField to `field1` and `field2`."); enabled = false; return; }
m_ExternalForcesModule = system.externalForces; m_ExternalForcesModule.enabled = true; m_ExternalForcesModule.influenceFilter = ParticleSystemGameObjectFilter.List; m_ExternalForcesModule.AddInfluence(field1); }
void OnGUI() { Debug.Assert(m_ExternalForcesModule.influenceCount == 1); var currentForceField = m_ExternalForcesModule.GetInfluence(0);
GUILayout.BeginHorizontal(); GUILayout.Label("Influence: " + currentForceField.name);
if (GUILayout.Button("Toggle")) { m_ExternalForcesModule.SetInfluence(0, currentForceField == field1 ? field2 : field1); }
GUILayout.EndHorizontal(); } }