Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    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:
    169
    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:
    906
    RequireComponent
     
    Volcanicus likes this.
  3. Volcanicus

    Volcanicus

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