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 kolalex01 · Oct 21, 2014 at 08:29 PM · guicharacterlistguibutton

How to add my character to characterlist?

Here's my code: using UnityEngine; using System.Collections;

 public class Characterlist : MonoBehaviour {
     public bool createcharacter;
     public float scrollbar;
     public bool choosecast;
     public float scrollbartwo;
     public string name = "";
     public bool showcharacter;
     // Use this for initialization
     void Start () {
         createcharacter = false;
         choosecast = false;
         showcharacter = false;
     }
     
     // Update is called once per frame
     void Update () {
     
     }
     void OnGUI ()
     {
         GUI.Box (new Rect (400, 10, 800, 800), "Character");
         if (GUI.Button (new Rect (500, 100, 600, 100), "Create new character"))
                         createcharacter = true;
         if (createcharacter) {
             scrollbar = GUI.HorizontalScrollbar (new Rect (30, 40, 100, 20), scrollbar, 1.0f, 5.0f, 1.0f);
             GUI.Label (new Rect (10, 10, 100, 40), "Class:");
             scrollbartwo = GUI.HorizontalScrollbar (new Rect (30, 90, 100, 20), scrollbartwo, 1.0f, 5.0f, 1.0f);
             GUI.Label (new Rect (10, 60, 100, 40), "Race:");
             GUI.Box (new Rect (0, 0, 200, 250), "");
             if (GUI.Button (new Rect (20, 200 ,150 , 40), "Create character"))
             {
                 createcharacter = false;
                 showcharacter = true;
                 if (showcharacter == true)
                 {
                     GUI.Box (new Rect (100, 100, 100, 100), "asd");
                 }
                 }
             }
         if (createcharacter) {
                         if (scrollbar == 4) {
                                 GUI.Label (new Rect (70, 10, 100, 40), "Mage");
                         }
                         if (scrollbar == 1) {
                                 GUI.Label (new Rect (70, 10, 100, 40), "Warrior");    
                         }
                         if (scrollbar < 4 && scrollbar > 1) {
                                 GUI.Label (new Rect (70, 10, 100, 40), "Ranger");
                         }
                         if (scrollbartwo == 4) {
                                 GUI.Label (new Rect (70, 60, 100, 40), "Human");
                         }
                         if (scrollbartwo == 1) {
                                 GUI.Label (new Rect (70, 60, 100, 40), "Orc");    
                         }
                         if (scrollbartwo < 4 && scrollbartwo > 1) {
                                 GUI.Label (new Rect (70, 60, 100, 40), "Elf");
                         }
             GUI.Label (new Rect (10, 150, 100, 40), "Name:");
             name = GUI.TextField (new Rect (70, 150, 50, 20), name);
                 }
 
     }
 }
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by esitoinatteso · Oct 21, 2014 at 09:17 PM

Pardon me, but I think you're doing something wrong... I mean with a wrong logic.

If you want to add a GameObject named " character" to a list, you have to first set up a list. This class of yours called Characterlist would be a good spot to do that.

Write this as your 3rd line ( it doesn't have to be the 3rd line, but it must be before the line in which is wrote: public class Characterlist : MonoBehaviour)

 using System.Collections.Generic;//This enables the Lists

Then add this in your class constructor:

 public List<GameObject> ListOfCharacters = new List<GameObject>();

This way you'll have a public list set up. In the editor you can drag and drop there your characters.

You could even do so by code.

This assumes you know what a Class, a GameObject and a List are. If you don't then I encourage you to have a look at these links:

Unity Lists VideoTutorial

Unity Manual: GameObject

Unity Classes VideoTutorial

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

Adding Item object to Inventory List 0 Answers

How to get a list of all the GUI elements in a scene? 1 Answer

multiplayer offline Character selection. Help? 0 Answers

Im trying to make a character jump when a GUI button is clicked on 1 Answer


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