Search Unity

Question Instantiate Object of Class for a list

Discussion in 'Scripting' started by MarlouShazu, Apr 2, 2023.

  1. MarlouShazu

    MarlouShazu

    Joined:
    Aug 5, 2020
    Posts:
    1
    I've created a little class to store my Moves, in a turn based combat system upload_2023-4-2_18-16-50.png

    Now i want to add four moves to my player prefab, to test it, but i need to create them somehow?
    upload_2023-4-2_18-18-16.png
    I cant seem to create objects with a script that inherits the Move class cuz it wont add to the little list there.
    I thought that i would have to just set the fields by hand in the list on the editor but it wants only a Move type object or something.
    Empty Object with a script won't do it, neither a prefab or simply just a script, so i'm lost here, what do i need to create to add there?
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,187
    My guess is you don't want Move to inherit from MonoBehaviour. So, either use scriptableObjects or just a regular class and use the SerializedField to make it so you can edit the fields in the editor. Otherwise, you'd have to attach a move script to your gameobject for each move they could do.
     
    DouglasPotesta likes this.
  3. Olipool

    Olipool

    Joined:
    Feb 8, 2015
    Posts:
    322
    In addition to the above, Unity does not serialize/show properties in the inspector. You have to create backing fields for them like:
    [SerializeField] private string moveName;
    public string MoveName => moveName;
     
    DouglasPotesta likes this.