Version: 2022.1
public ParticleSystem.LightsModule lights ;

描述

粒子系统 LightsModule 的脚本接口。

通过此模块可将实时光源附加到一部分粒子。

光源模块是一种简单而强大的模块,使粒子可以方便地将光投射到其环境上。光源可以从它们所附加到的粒子继承属性(如颜色和大小)。支持点光源和聚光灯,包括阴影投射和灯光遮罩。

不需要将粒子系统模块重新分配回系统;它们是接口而不是独立的对象。

using UnityEngine;
using System.Collections;

[RequireComponent(typeof(ParticleSystem))] public class ExampleClass : MonoBehaviour {

public Light lightPrefab;

void Start() { ParticleSystem ps = GetComponent<ParticleSystem>(); var lights = ps.lights; lights.enabled = true; lights.ratio = 0.5f; lights.light = lightPrefab; } }