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 Dethl · Feb 27, 2011 at 03:02 AM · onguienumlabel

Character Creation GUI label...Even and Odd question

Hi :D! well this is not an error, I just want to know something....

I have been following the Hack 'n Slash tutorials I'm currently in the Character Creation step In video 23, In this step we create the Character creation Label where you set your Character's Name and distribute you points blah,blah whatever XD I want to Display my Defense and Attack Skills in two different columns, One with all the defense Skills and another with all the Attack ones...Something like this :

Skills:

      Offense              Defense 
     Melee Offense   0   Melee Defense   0 
     Ranged Offense  0   Ranged Defense  0
     Magic Offense   0   Magic Defense   0
     Mental Offense  0   Mental Defense  0

This is my Character Generator Script:

using UnityEngine; using System.Collections; using System;

public class CharacterGenerator : MonoBehaviour { private PlayerCharacter _toon;

 // Use this for initialization
 void Start () {
     _toon = new PlayerCharacter();
     _toon.Awake();

 }

 // Update is called once per frame
 void Update () {


 }

 void OnGUI() {

     DisplayName();
     DisplayStatics();
     DisplayVitals();
     DisplaySkills();
 }

 private void DisplayName() {
     GUI.Label(new Rect(10, 10, 50, 20), "Name:");
     _toon.Name = GUI.TextArea(new Rect(65, 10, 100, 25), _toon.Name);
 }

 private void DisplayStatics()
 {
     for (int count = 0; count < Enum.GetValues(typeof(AttrbutionsName)).Length; count++)
     {

         GUI.Label(new Rect(10, 50 + (count * 25), 100, 25), ((AttrbutionsName)count).ToString());
         GUI.Label(new Rect(115, 50 + (count * 25), 30, 25), _toon.GetPrimaryAttribute(count).AdjustedBaseValue.ToString());

     }
 }

 private void DisplayVitals()
 {
     for (int count = 0; count < Enum.GetValues(typeof(VitalName)).Length; count++)
     {

         GUI.Label(new Rect(10, 260 + (count * 25), 100, 25), ((VitalName)count).ToString());
         GUI.Label(new Rect(115, 260 + (count * 25), 30, 25), _toon.GetVital(count).AdjustedBaseValue.ToString());

     }
 }

 private void DisplaySkills()
 {
     for (int count = 0; count < Enum.GetValues(typeof(SkillsNames)).Length; count++)
     {

         GUI.Label(new Rect(250, 50 + (count * 25), 200, 25), ((SkillsNames)count).ToString());
         GUI.Label(new Rect(365, 50 + (count * 25), 30, 25), _toon.GetSkill(count).AdjustedBaseValue.ToString());

     }
 }

}

And This is my Skills Script:

public class Skill : ModifiedStat { private bool _known;

 public Skill()
 {
     _known = false;
     ExpTopLevel = 25;
     LevelModifier = 1.1f;
 }

 public bool Known {
     get{return _known;}
     set { _known = value; }
 }

} public enum SkillsNames { //Melee Skills
Melee_Offense, Melee_Defense, //Range Skills Ranged_Offense, Ranged_defense, //Magic Skills Magic_Offense, Magic_Defense, //Mental Skills Mental_Offense, Mental_Defense }

My Scripts Are a little personalized so they aren't totally the same than the ones in the tutorial ;D

Well now here it comes my idea of how to do it....All the Offense Skills are Odd Numbers, and all the Defense Skills are Even Numbers, So I want two functions like this one:

private void DisplaySkills() {
        for (int count = 0; count < Enum.GetValues(typeof(SkillsNames)).Length; count++)
        {
            GUI.Label(new Rect(250, 50 + (count * 25), 200, 25), ((SkillsNames)count).ToString());
            GUI.Label(new Rect(365, 50 + (count * 25), 30, 25), _toon.GetSkill(count).AdjustedBaseValue.ToString());
        }
    }

But I need one that only gets the Odd numbers of the Enumeration,and another that only gets the Even numbers of the Enumeration...Is That Possible? Can you Help me? Can this be solved? Will you answer my questions?....Lets figure it out in the next Answer XD

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
1
Best Answer

Answer by Demigiant · Feb 27, 2011 at 02:28 PM

I'm not exactly sure of what you're asking, but if you simply want to store odd numbers in an Array, and even numbers in another, this is simply done with:

if ( mynumber % 2 == 0 ) {
  // Even number... store it in Array A or else
} else {
  // Odd number... store it in Array B or else else :P
}

If this isn't what you wanted, and I didn't understand: sorry :)

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 Dethl · Feb 28, 2011 at 01:05 AM 0
Share

Thanks I got it :D it wasn't exactly what i needed but it helped me to come out with a solution ;D

avatar image Demigiant · Feb 28, 2011 at 08:41 AM 0
Share

Then I'm glad I gave you the right wrong answer ;D

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

No one has followed this question yet.

Related Questions

OnGUI called after LateUpdate screwing up debug text database 1 Answer

GUI set max amount of characters for Label 1 Answer

How do I make onMouseDown work for OnGUI in C#? 1 Answer

I keep getting an error on my for loop. 1 Answer

Making scrollbar for GUI.Label inside a draggable GUI.Window 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