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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

(c#)Switching between two characters mid game.

Discussion in 'Scripting' started by DarkBladeNemo, Mar 17, 2019.

  1. DarkBladeNemo

    DarkBladeNemo

    Joined:
    Aug 23, 2013
    Posts:
    116
    I am looking for a way to change between two characters mid game. Basically I want the game to start and lets say I start with Character A then if I press a button I switch to Character B with camera and all. I recently came back to Unity after messing with Unreal engine and they have a very simple possession system for doing this but I am unsure how to approach this situation in Unity.

    I have Googled it and found a few things but they are all from a few years back. One of which was basically working with disabling everything on the one character and enabling it on the other. I figure that might work but there has to be a more simpler way of going about it instead of writing 90 lines of code.

    Thank you in advance
     
  2. ihgyug

    ihgyug

    Joined:
    Aug 5, 2017
    Posts:
    193
    It really depends on the characters, there is no common way to do such task.

    If the characters are simple enough, you may just want to swap a sprite or whatever component and done.

    If the characters are more complex, you may want to have the data of the characters in the form of Scriptable Objects, and then based on that data, change things accordingly, instead of simply adding new functionality to each character separately.

    If the characters are very complex and different from each other, maybe having multiple custom prefabs and disabling and enabling when needed can be considered (the one you mentioned).

    90 lines of code are not that much :p
     
  3. DarkBladeNemo

    DarkBladeNemo

    Joined:
    Aug 23, 2013
    Posts:
    116
    Well they would be in 3d the characters aren't all that different. The only difference is the mesh and basically what they can interact with.