Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Valon · Jan 23, 2014 at 09:01 PM · characterscreenswitchrpgselection

Switching between multiple classes

Hello,

I'm currently working on a game where I want the player to be able to choose (before the start of the game) a character. It's a fantasy game so it's basically a mage and a warrior so far. Note that it's in another scene that the choice is made and not in the level.

It works kinda like Skyrim with a First Person View so I have no models.

I have a character selection screen that brings me to the level 1 but my biggest problem is te object switching between the two characters since they have a whole bunch of scripts attached to them and I don't really know how to disable everything from 1 to use everything from the other. My characters move at different speeds, don't have the same life or mana or anything really.

I figured I probably don't have to switch camera since I want to spawn exactly at the same place for both but except this part I don't really know what I should do. I really want to remove everything linked to the mage from the world if the warrior is called for example and a simple Destroy object doesn't work.

Can you help me with this one?

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Benproductions1 · Jan 23, 2014 at 10:35 PM 1
Share

Just a note: Your two characters (in fact, all of them) should have the same script/class, or at least inherit from the same class. That means you can generalize world interactions and don't have to switch scripts depending on which character the player has chosen.

avatar image Valon · Jan 23, 2014 at 11:32 PM 0
Share

Well, they do have the same basics yeah like some part of their mouvements or some part of the GUI but my mage as a few spells that I have to disable for my warrior for example. Anyways I think I found the solution I destroy the object I don't need and I put "if($$anonymous$$age)" with a public static bool variable everywhere in the scripts for the part I don't need to have for the warrior. But not being a programmer, I have a feeling that it is an ugly way to do it.

avatar image Benproductions1 · Jan 23, 2014 at 11:53 PM 1
Share

Yes, that is a very ugly way of doing it. I already mentioned inheritance as a good way of doing it. I don't know anything about how it's supposed to be set up, but maybe you should try inheritance.

avatar image Valon · Jan 24, 2014 at 01:29 AM 0
Share

I'll try to look into it, I'm not too familiar with inheritance I just know the basic concept.

Thank you.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by blank_reg · Jan 24, 2014 at 12:05 AM

You could use SetActive on your characters. Read about it in the Scripting Reference

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Valon · Jan 24, 2014 at 01:29 AM 0
Share

I tried before posting here but it didn't work like I wanted too.

avatar image blank_reg · Jan 24, 2014 at 01:50 AM 0
Share

maybe you can post your code, or link to original posting if there is code there. It should be pretty straightforward.

avatar image
0

Answer by Valon · Jan 24, 2014 at 02:40 AM

Ok so this is the character spawner :

 int savedPlayer = 0;
     GameObject Character1;
     GameObject Character2;
     public static bool isMage = true;
         
     bool isPrincipal = false;
 void Awake()
     {
         Character1 = GameObject.Find ("Mage");
         Character2 = GameObject.Find ("Guerrier");
 
         savedPlayer = PlayerPrefs.GetInt ("selected Character");
         if (savedPlayer == 1) {
                         
                         Character1.SetActive(true); 
                         GameObject.Destroy(Character2); 
                         isMage = true;
                 }
         if (savedPlayer == 2) {
             Character2.SetActive(true); 
             GameObject.Destroy(Character1);
             isMage = false;
 
                 }
         if (savedPlayer == 0) {
             Character1.SetActive(true); 
             GameObject.Destroy(Character2); 
 
             isMage = true;
             }
                 } 
 
     }


And this is the character selector, I actually used SetActive but I think it's the part where it has to put is to false that doesn't work :

 public bool isCharacter1 = false;
 public bool isCharacter2 = false;
 public bool isCharacter3 = false;
 public bool isCharacter4 = false;

 int nbCharacter = 4;
 int selectedCharacter = 0;


 void OnMouseUp()
 {

     if (isCharacter1) {
                     selectedCharacter = 1;
                     PlayerPrefs.SetInt("selected Character", selectedCharacter);
                     Application.LoadLevel("Tomjeu");            
             }
     if (isCharacter2) {
                     selectedCharacter = 2;
         PlayerPrefs.SetInt("selected Character", selectedCharacter);
         Application.LoadLevel("Tomjeu");
             }
     if (isCharacter3) {
                     selectedCharacter = 3;
         PlayerPrefs.SetInt("selected Character", selectedCharacter);
             }
     if (isCharacter4) {
                     selectedCharacter = 4;
         PlayerPrefs.SetInt("selected Character", selectedCharacter);
             }
 }

}

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Realtime object loading to scene 1 Answer

switch character 1 Answer

Recommendation for very simple character customization? 0 Answers

Rerolling RPG Character Attributes With Limits 1 Answer

Character Selection 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges