Version: 2021.2
public ParticleSystemForceField GetInfluence (int index);

参数

index 要返回所选力场的索引。

返回

ParticleSystemForceField 列表中的 ForceField。

描述

获得影响因子列表中给定索引位置的 ParticleSystemForceField

influenceFilter 设置为 ParticleSystemGameObjectFilter.List 时,只有影响因子列表中的力场才会影响粒子系统。

using UnityEngine;

public class Example : MonoBehaviour { ParticleSystem.ExternalForcesModule externalForcesModule;

void Start() { // Create a default particle system var particleSystemGameObject = new GameObject("Particle System"); var system = particleSystemGameObject.AddComponent<ParticleSystem>();

// Create a force field to influence the particle system var forceFieldGameObject = new GameObject("Force Field"); var forceField = forceFieldGameObject.AddComponent<ParticleSystemForceField>(); forceField.endRange = 5; forceFieldGameObject.transform.position = new Vector3(0, 0, 10);

// Add the force to the particle systems external forces influencers. externalForcesModule = system.externalForces; externalForcesModule.enabled = true; externalForcesModule.influenceFilter = ParticleSystemGameObjectFilter.List; externalForcesModule.AddInfluence(forceField); }

void OnGUI() { GUILayout.Label("Particle System Influencers:"); for (int i = 0; i < externalForcesModule.influenceCount; ++i) { var influence = externalForcesModule.GetInfluence(i); GUILayout.Label(i + ": " + influence.name); } } }