Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Protoyon · Jan 10, 2016 at 06:23 PM · c#character

Character Selection

Hello! I created a few characters, in which I'd like the player to choose from, I created a script which will allow the player to "scroll" through the characters using the right arrow, however, I am only able to scroll once, before it stops working.

My script is most likely very poorly made, I am rather new with C#, I put all the characters at the same location, and set them inactive, except for the first one. I made an if statement, detecting if a character was active, and the arrow has been pushed, then it will shuffle to the next character. This however didn't work, is there a better way?

Here is the Script: (Sorry for the mess)

 using UnityEngine;
 using System.Collections;
 
 public class CharacterSelection : MonoBehaviour {
 
     public GameObject BlackHairBlueShirtBluePants;
     public GameObject BlackHairBlueShirtGreyPants;
     public GameObject BlondeHairBlueShirtBluePants;
     public GameObject BlondeHairBlueShirtGreyPants;
     public GameObject BrownHairBlueShirtBluePants;
     public GameObject BrownHairBlueShirtGreyPants;
 
     public bool hair;
     public bool shirt;
     public bool pants;
 
     void Start () {
         BlackHairBlueShirtBluePants.SetActive(true);
         BlackHairBlueShirtGreyPants.SetActive(false);
         BlondeHairBlueShirtBluePants.SetActive(false);
         BlondeHairBlueShirtGreyPants.SetActive(false);
         BrownHairBlueShirtBluePants.SetActive(false);
         BrownHairBlueShirtGreyPants.SetActive(false);
         hair = true;
     }
     void Update()
     {
         hair = true;
         if(Input.GetButtonDown("Interact1"))
         {
             if (hair)
             {
                 hair = false;
                 pants = true;
             }
             if (pants)
             {
                 pants = false;
                 shirt = true;
             }
             if (shirt)
             {
                 shirt = false;
                 hair = true;
             }
         }
         if (Input.GetButtonDown("Interact") && hair)
         {
             if(BlackHairBlueShirtBluePants.activeSelf)
             {
                 BlackHairBlueShirtBluePants.SetActive(false);
                 BlondeHairBlueShirtBluePants.SetActive(true);
             }
             if (BlondeHairBlueShirtBluePants.activeSelf)
             {
                 BlondeHairBlueShirtBluePants.SetActive(false);
                 BrownHairBlueShirtBluePants.SetActive(true);
             }
             if (BrownHairBlueShirtBluePants.activeSelf)
             {
                 BrownHairBlueShirtBluePants.SetActive(false);
                 BlondeHairBlueShirtBluePants.SetActive(true);
             }
             if (BlackHairBlueShirtGreyPants.activeSelf)
             {
                 BlackHairBlueShirtGreyPants.SetActive(false);
                 BlondeHairBlueShirtGreyPants.SetActive(true);
             }
             if (BlondeHairBlueShirtGreyPants.activeSelf)
             {
                 BlondeHairBlueShirtGreyPants.SetActive(false);
                 BrownHairBlueShirtGreyPants.SetActive(true);
             }
             if (BrownHairBlueShirtGreyPants.activeSelf)
             {
                 BrownHairBlueShirtGreyPants.SetActive(false);
                 BlondeHairBlueShirtGreyPants.SetActive(true);
             }
 
         }
         if (Input.GetButtonDown("Horizontal") && pants)
         {
             if (BlackHairBlueShirtBluePants.activeSelf)
             {
                 BlackHairBlueShirtBluePants.SetActive(false);
                 BlackHairBlueShirtGreyPants.SetActive(true);
             }
             if (BlackHairBlueShirtGreyPants.activeSelf)
             {
                 BlackHairBlueShirtGreyPants.SetActive(false);
                 BlackHairBlueShirtBluePants.SetActive(true);
             }
             if (BrownHairBlueShirtBluePants.activeSelf)
             {
                 BrownHairBlueShirtBluePants.SetActive(false);
                 BrownHairBlueShirtGreyPants.SetActive(true);
             }
             if (BrownHairBlueShirtGreyPants.activeSelf)
             {
                 BrownHairBlueShirtGreyPants.SetActive(false);
                 BrownHairBlueShirtBluePants.SetActive(true);
             }
             if (BlondeHairBlueShirtBluePants.activeSelf)
             {
                 BlondeHairBlueShirtBluePants.SetActive(false);
                 BlondeHairBlueShirtGreyPants.SetActive(true);
             }
             if (BlondeHairBlueShirtGreyPants.activeSelf)
             {
                 BlondeHairBlueShirtGreyPants.SetActive(false);
                 BlondeHairBlueShirtBluePants.SetActive(true);
             }
 
         }
     }
     
 }
 

Comment
Add comment · Show 3
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 corn · Jan 10, 2016 at 06:40 PM 1
Share

Please post your script anyway, it'll be easier to understand what you tried to achieve, and it can probably be fixed.

avatar image vintar · Jan 10, 2016 at 09:45 PM 1
Share

remove hair = true; from the update method else if (Input.GetButtonDown("Interact") && hair) will always be true.

avatar image Protoyon vintar · Jan 11, 2016 at 02:58 PM 0
Share

I dont remember if I added hair = true to the update function after my issue as an attempt to fix it, but I will try that when I get home.

0 Replies

· Add your reply
  • Sort: 

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

66 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

restricting player movement with a path? 1 Answer

I want to add some Velocity controll to my CharacterController 1 Answer

fps script not working 1 Answer

Issue with Rigidbody2D (I think) 2 Answers

I have my animations created. Now what? 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