NWH Common
Search Results for

    Show / Hide Table of Contents

    Class VehicleChanger

    Manages switching between multiple vehicles in a scene with support for both instant and character-based (enter/exit) modes.

    Inheritance
    object
    Object
    Component
    Behaviour
    MonoBehaviour
    VehicleChanger
    Namespace: NWH.Common.SceneManagement
    Assembly: NWH.Common.dll
    Syntax
    [DefaultExecutionOrder(500)]
    public class VehicleChanger : MonoBehaviour
    Remarks

    VehicleChanger supports two modes: - Instant switching: Press a button to cycle through vehicles immediately - Character-based: Player must walk to a vehicle and enter/exit at designated points

    In character-based mode, the player can only enter vehicles when near an EnterExitPoint and the vehicle is moving slowly enough. This creates more realistic vehicle switching similar to GTA-style games.

    Inactive vehicles can optionally be put to sleep to improve performance when managing many vehicles in a scene.

    Fields

    | Edit this page View Source

    activeVehicleIndex

    Index of the current vehicle in vehicles list.

    Declaration
    [Tooltip("    Index of the current vehicle in vehicles list.")]
    public int activeVehicleIndex
    Field Value
    Type Description
    int
    | Edit this page View Source

    characterBased

    Is vehicle changing character based? When true changing vehicles will require getting close to them to be able to enter, opposed to pressing a button to switch between vehicles.

    Declaration
    [Tooltip("Is vehicle changing character based? When true changing vehicles will require getting close to them\r\nto be able to enter, opposed to pressing a button to switch between vehicles.")]
    public bool characterBased
    Field Value
    Type Description
    bool
    | Edit this page View Source

    characterObject

    Game object representing a character. Can also be another vehicle.

    Declaration
    [Tooltip("    Game object representing a character. Can also be another vehicle.")]
    public GameObject characterObject
    Field Value
    Type Description
    GameObject
    | Edit this page View Source

    enterDistance

    Maximum distance at which the character will be able to enter the vehicle.

    Declaration
    [Range(0.2, 3)]
    [Tooltip("    Maximum distance at which the character will be able to enter the vehicle.")]
    public float enterDistance
    Field Value
    Type Description
    float
    | Edit this page View Source

    enterExitTag

    Tag of the object representing the point from which the enter distance will be measured. Useful if you want to enable you character to enter only when near the door.

    Declaration
    [Tooltip("Tag of the object representing the point from which the enter distance will be measured. Useful if you want to enable you character to enter only when near the door.")]
    public string enterExitTag
    Field Value
    Type Description
    string
    | Edit this page View Source

    location

    When the location is Near, the player can enter the vehicle.

    Declaration
    [Tooltip("When the location is Near, the player can enter the vehicle.")]
    public VehicleChanger.CharacterLocation location
    Field Value
    Type Description
    VehicleChanger.CharacterLocation
    | Edit this page View Source

    maxEnterExitVehicleSpeed

    Maximum speed at which the character will be able to enter / exit the vehicle.

    Declaration
    [Tooltip("    Maximum speed at which the character will be able to enter / exit the vehicle.")]
    public float maxEnterExitVehicleSpeed
    Field Value
    Type Description
    float
    | Edit this page View Source

    onDeactivateAll

    Event invoked when all vehicles are deactivated (e.g., when exiting in character-based mode).

    Declaration
    public UnityEvent onDeactivateAll
    Field Value
    Type Description
    UnityEvent
    | Edit this page View Source

    onVehicleChanged

    Event invoked whenever the active vehicle changes.

    Declaration
    public UnityEvent onVehicleChanged
    Field Value
    Type Description
    UnityEvent
    | Edit this page View Source

    putOtherVehiclesToSleep

    Should the vehicles that the player is currently not using be put to sleep to improve performance?

    Declaration
    [Tooltip("    Should the vehicles that the player is currently not using be put to sleep to improve performance?")]
    public bool putOtherVehiclesToSleep
    Field Value
    Type Description
    bool
    | Edit this page View Source

    startInVehicle

    Should the player start inside the vehicle?

    Declaration
    [Tooltip("Should the player start inside the vehicle?")]
    public bool startInVehicle
    Field Value
    Type Description
    bool
    | Edit this page View Source

    vehicles

    List of all of the vehicles that can be selected and driven in the scene.

    Declaration
    [Tooltip("List of all of the vehicles that can be selected and driven in the scene.")]
    public List<Vehicle> vehicles
    Field Value
    Type Description
    List<Vehicle>

    Properties

    | Edit this page View Source

    Instance

    Declaration
    public static VehicleChanger Instance { get; }
    Property Value
    Type Description
    VehicleChanger

    Methods

    | Edit this page View Source

    ChangeVehicle(Vehicle)

    Switches to the specified vehicle if it exists in the vehicles list.

    Declaration
    public void ChangeVehicle(Vehicle ac)
    Parameters
    Type Name Description
    Vehicle ac

    Vehicle reference to switch to.

    | Edit this page View Source

    ChangeVehicle(int)

    Changes vehicle to requested vehicle.

    Declaration
    public void ChangeVehicle(int index)
    Parameters
    Type Name Description
    int index

    Index of a vehicle in Vehicles list.

    | Edit this page View Source

    DeactivateAllExceptActive()

    Enables the current active vehicle and optionally disables all others based on putOtherVehiclesToSleep setting.

    Declaration
    public void DeactivateAllExceptActive()
    | Edit this page View Source

    DeactivateAllIncludingActive()

    Disables all managed vehicles including the currently active one. Used when exiting vehicles in character-based mode.

    Declaration
    public void DeactivateAllIncludingActive()
    | Edit this page View Source

    DeregisterVehicle(Vehicle)

    Removes a vehicle from the managed vehicles list. If the vehicle was active, automatically switches to the next vehicle.

    Declaration
    public void DeregisterVehicle(Vehicle v)
    Parameters
    Type Name Description
    Vehicle v

    Vehicle to deregister.

    | Edit this page View Source

    EnterVehicle(Vehicle)

    Puts the player inside the specified vehicle and activates it. In character-based mode, stores the entry position for later exit.

    Declaration
    public void EnterVehicle(Vehicle v)
    Parameters
    Type Name Description
    Vehicle v

    Vehicle to enter.

    | Edit this page View Source

    ExitVehicle(Vehicle)

    Removes the player from the vehicle and spawns the character object nearby. Character is positioned at the stored entry location.

    Declaration
    public void ExitVehicle(Vehicle v)
    Parameters
    Type Name Description
    Vehicle v

    Vehicle to exit.

    | Edit this page View Source

    NextVehicle()

    Switches to the next vehicle in the list, wrapping to the first vehicle when reaching the end.

    Declaration
    public void NextVehicle()
    | Edit this page View Source

    PreviousVehicle()

    Switches to the previous vehicle in the list, wrapping to the last vehicle when at the beginning.

    Declaration
    public void PreviousVehicle()
    | Edit this page View Source

    RegisterVehicle(Vehicle)

    Adds a vehicle to the managed vehicles list if not already present. Newly registered vehicles are automatically disabled unless they are the active vehicle.

    Declaration
    public void RegisterVehicle(Vehicle v)
    Parameters
    Type Name Description
    Vehicle v

    Vehicle to register.

    • Edit this page
    • View Source
    In this article
    Back to top Copyright © NWH - Vehicle Physics, Aerodynamics, Dynamic Water Physics