Search Unity

Question Several Monster Models (Spawn)

Discussion in 'Scripting' started by Atsutake, Mar 13, 2023.

  1. Atsutake

    Atsutake

    Joined:
    Mar 8, 2023
    Posts:
    18
    Hello all,

    I was about to start adding simple AI scripts onto my entity prefab and its model. But how to do this if you have different monster models while their scripts are the same? Do I have to create a prefab and link the same script for every monster model? It would be great if there is a way to do it with only one prefab, so I can spawn certain variant of the prefab. Maybe Instantiate and attach model to prefab while mirror spawns the prefab?
     
  2. AngryProgrammer

    AngryProgrammer

    Joined:
    Jun 4, 2019
    Posts:
    490
    1. In Unity, we distinguish Prefabs and Variants.
    2. A prefab can be, for example, a basic model containing elementary components (something like a base class, but don't has to).
    3. A variant, on the other hand, can be something more specialized based on a prefab (i.e. something like an inheriting class).
    4. If you have an enemy spawn script, you can put a public List<GameObject> in it, and then add more prefabs/variants to the list (by dragging and dropping).
    5. Now you can think of a way to spawn enemies, e.g. randomly by selecting an index from a range in the list or according to a specific scenario/pattern.
    6. You can place different monster AI behaviors through components (each Variant can have different component).
     
    Last edited: Mar 13, 2023
    Atsutake likes this.