NWH Vehicle Physics 2
Search Results for

    Show / Hide Table of Contents

    Class LightSource

    Represents a single vehicle light source that can be implemented as either a Unity Light component or an emissive mesh material for headlights, brake lights, turn signals, and other vehicle illumination.

    Inheritance
    object
    LightSource
    Namespace: NWH.VehiclePhysics2.Effects
    Assembly: NWH.VehiclePhysics2.dll
    Syntax
    [Serializable]
    public class LightSource
    Remarks

    LightSource provides a unified interface for controlling both traditional Unity Light components and emissive mesh materials. This allows for flexible lighting setups where some lights use actual illumination (Light mode) while others use visual-only emissive materials (Mesh mode).

    Light mode uses Unity's light system for actual scene illumination, suitable for headlights and searchlights. Mesh mode modifies material emission properties for visual indication without scene lighting, ideal for brake lights, turn signals, and decorative lighting where performance is prioritized.

    The light source can be controlled through intensity values and supports HDR colors for realistic automotive lighting effects. Emission color and intensity are automatically synchronized with the underlying Light or Material components.

    Fields

    emissionColor

    The HDR color of the emitted light or emissive material. Supports high dynamic range values for realistic bright automotive lighting effects. Used by both Light mode (tints the light color) and Mesh mode (sets material emission color).

    Declaration
    [ColorUsage(true, true)]
    [Tooltip("The color of the emitted light.")]
    public Color emissionColor
    Field Value
    Type Description
    Color

    isOn

    Gets whether the light source is currently turned on. Updated by TurnOn() and TurnOff() methods.

    Declaration
    [NonSerialized]
    public bool isOn
    Field Value
    Type Description
    bool

    light

    Unity Light component (Point/Spot/Directional) for actual scene illumination. Only used when type is set to Light. Provides real lighting but has higher performance cost. Ideal for headlights and searchlights that need to illuminate the environment.

    Declaration
    [Tooltip("Light (point/spot/directional/etc.) representing the vehicle light. Will only be used if light type is set to\r\nLight.")]
    public Light light
    Field Value
    Type Description
    Light

    meshRenderer

    MeshRenderer with emissive material for visual-only light indication. Only used when type is set to Mesh. Modifies material emission without scene lighting. Better performance than Light mode. Ideal for brake lights, indicators, and decorative lighting. Material must support emission (Standard shader or HDRP Lit shader).

    Declaration
    [Tooltip("Mesh renderer using standard shader. Emission on the material will be turned on or off depending on light state.")]
    public MeshRenderer meshRenderer
    Field Value
    Type Description
    MeshRenderer

    onLightTurnedOff

    Called when the light is turned off.

    Declaration
    [Tooltip("Called when the light is turned off.")]
    public UnityEvent onLightTurnedOff
    Field Value
    Type Description
    UnityEvent

    onLightTurnedOn

    Called when the light is turned on.

    Declaration
    [Tooltip("Called when the light is turned on.")]
    public UnityEvent onLightTurnedOn
    Field Value
    Type Description
    UnityEvent

    rendererMaterialIndex

    Material array index to modify when the MeshRenderer has multiple materials. Use 0 for single-material meshes. Only relevant when type is set to Mesh.

    Declaration
    [Tooltip("If your mesh has more than one material, set this number to the index of the required material.")]
    public int rendererMaterialIndex
    Field Value
    Type Description
    int

    type

    Type of the light.

    Declaration
    [Tooltip("Type of the light.")]
    public LightSource.LightType type
    Field Value
    Type Description
    LightSource.LightType

    Methods

    TurnOff()

    Turns off the light source by disabling the Light component or removing material emission. Invokes onLightTurnedOff event. Has no effect if already off.

    Declaration
    public virtual void TurnOff()

    TurnOn()

    Turns on the light source by enabling the Light component or applying material emission. Invokes onLightTurnedOn event. Has no effect if already on.

    Declaration
    public virtual void TurnOn()
    In this article
    Back to top Copyright © NWH - Vehicle Physics, Aerodynamics, Dynamic Water Physics