Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Imposing components when script is added to game object

Discussion in 'Scripting' started by Volcanicus, Jun 26, 2019.

  1. Volcanicus

    Volcanicus

    Joined:
    Jan 6, 2018
    Posts:
    165
    I found this awhile back and saw it being used however i lost it and I cannot find it through keywords alone.
    What is the script code to impose a component on a game object?

    For instance, the second I attach script "NavMeshController", I would like a NavMesh Component and a Collider to be attached as well.

    I know you can check if these components exist and create a warning/error but how do I impose it?
     
  2. ThermalFusion

    ThermalFusion

    Joined:
    May 1, 2011
    Posts:
    837
    RequireComponent
     
    Volcanicus likes this.
  3. Volcanicus

    Volcanicus

    Joined:
    Jan 6, 2018
    Posts:
    165
    Thank you!