Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Switching between characters using Scriptable objects

Discussion in 'Scripting' started by unity_3V704ypuwX7kQA, Dec 20, 2020.

  1. unity_3V704ypuwX7kQA

    unity_3V704ypuwX7kQA

    Joined:
    Dec 20, 2020
    Posts:
    5
    Hi, I need some help on how to make a system where you can change characters that have different speeds and powers using Scriptable objects but making it so the character's position stays the same. I have searched the web for this but nothing has come up.
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
    Give your character a function like
    Code (CSharp):
    1. public void PopulateStatsFrom(MyScriptableObject so) {
    2.   // Read all the data from the SO into your character here
    3. }
     
  3. unity_3V704ypuwX7kQA

    unity_3V704ypuwX7kQA

    Joined:
    Dec 20, 2020
    Posts:
    5
    Thanks for that but lets say my scriptabel object sample would have this


    public new string name;
    public float speed;
    public float maxhealth;
    public Sprite sprite;
    public int attack;
    public string type;

    It does no work and only has this:

    upload_2020-12-21_14-48-26.png
     
  4. unity_3V704ypuwX7kQA

    unity_3V704ypuwX7kQA

    Joined:
    Dec 20, 2020
    Posts:
    5
    For some reason only the public string name gets picked and the end curly brackets go back a tab
     
  5. unity_3V704ypuwX7kQA

    unity_3V704ypuwX7kQA

    Joined:
    Dec 20, 2020
    Posts:
    5
    Sorry if i didnt get what you were trying to say. I have just begun c# but not programing so I know a bit.