版本: Unity 6 (6000.0)
语言英语
  • C#

ParticleSystem.ExternalForcesModule.influenceMask

建议更改

成功!

感谢您帮助我们提高 Unity 文档的质量。虽然我们不能接受所有提交的内容,但我们会阅读用户提出的每项建议更改,并在适用的情况下进行更新。

关闭

提交失败

由于某种原因,您的建议更改无法提交。请<a>稍后再试</a>。感谢您抽出时间帮助我们提高 Unity 文档的质量。

关闭

取消

切换到手册
public LayerMask influenceMask;

描述

具有匹配层的粒子系统力场组件会影响此粒子系统。

其他资源:LayerMask

using UnityEngine;

[RequireComponent(typeof(ParticleSystem))] public class ExampleClass : MonoBehaviour { private ParticleSystem ps; public bool layerToggle; private readonly int layer0 = 0; private readonly int layer1 = 1;

void Start() { ps = GetComponent<ParticleSystem>();

var main = ps.main; main.startColor = Color.red;

var shape = ps.shape; shape.enabled = false;

var externalForces = ps.externalForces; externalForces.enabled = true;

var forceField1 = new GameObject("Force Field 1", typeof(ParticleSystemForceField)).GetComponent<ParticleSystemForceField>(); forceField1.transform.parent = ps.transform; forceField1.transform.localPosition = new Vector3(-3.0f, 0.0f, 3.0f); forceField1.transform.localRotation = Quaternion.Euler(0.0f, 0.0f, 180.0f); forceField1.transform.localScale = new Vector3(5.0f, 5.0f, 5.0f); forceField1.gameObject.layer = layer0;

forceField1.gravity = 0.04f; forceField1.rotationSpeed = 2.0f; forceField1.rotationAttraction = 0.02f;

var forceField2 = new GameObject("Force Field 2", typeof(ParticleSystemForceField)).GetComponent<ParticleSystemForceField>(); forceField2.transform.parent = ps.transform; forceField2.transform.localPosition = new Vector3(3.0f, 0.0f, 3.0f); forceField2.transform.localRotation = Quaternion.identity; forceField2.transform.localScale = new Vector3(5.0f, 5.0f, 5.0f); forceField2.gameObject.layer = layer1;

forceField2.gravity = 0.04f; forceField2.rotationSpeed = 2.0f; forceField2.rotationAttraction = 0.02f; }

void Update() { var externalForces = ps.externalForces; externalForces.influenceMask = layerToggle ? (1 << layer0) : (1 << layer1); }

void OnGUI() { layerToggle = GUI.Toggle(new Rect(25, 40, 100, 30), layerToggle, "Toggle Layer"); } }