Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 Jan_Julius · Jul 05, 2015 at 12:38 PM · arrayprogramminginheritancepokemon

Pokemon declaring types

I'm currently making a Pokémon clone for funsies

Now I went to declare pokemons, depedning on the pokedex number I set the name etc, now I want to set the Types, what is the best way to do this considering pokemon can have 1 or 2 types.

What I did(just want tips on how to improve):

my pokemon class:

 using UnityEngine;
 using System.Collections;
 
 public class Pokemon {
 
     /// <summary>
     /// Name of the pokémon
     /// </summary>
     public string name = "";
     /// <summary>
     /// Nickname of the pokémon
     /// </summary>
     public string nickname = "";
     /// <summary>
     /// Pokédex entry number of the Pokémon
     /// </summary>
     public string pokedexEntry = "";
     /// <summary>
     /// Pokedex Number of the Pokémon
     /// </summary>
     public int pokedexNumber = 0;
     /// <summary>
     /// Nature of the Pokémon
     /// </summary>
     public int nature = 0;
     /// <summary>
     /// height of the pokemon (in centimeters)
     /// </summary>
     public float height = 0;
     /// <summary>
     /// Weight of the Pokémon in kilograms
     /// </summary>
     public float weight = 0;
     /// <summary>
     /// gender of the pokemon 0 = male, 1 = female.
     /// </summary>
     public int gender = 0;
     /// <summary>
     /// level of the pokemon
     /// </summary>
     public int level = 1;
     /// <summary>
     /// what item the pokmeon holds 0 = no item
     /// </summary>
     public int holdItem = 0;
 
     /// <summary>
     /// health stat of the pokemon
     /// </summary>
     public int hp = 1;
     /// <summary>
     /// static health stat of the pokemon
     /// </summary>
     public int statichp = 1;
     /// <summary>
     /// atk stat of the pokemon
     /// </summary>
     public int atk = 1;
     /// <summary>
     /// static atk stat of the pokemon
     /// </summary>
     public int staticatk = 1;
     /// <summary>
     /// def stat of the pokemon
     /// </summary>
     public int def = 1;
     /// <summary>
     /// static def stat of the pokemon
     /// </summary>
     public int staticdef = 1;
     /// <summary>
     /// special attack stat of the pokemon
     /// </summary>
     public int spatk = 1;
     /// <summary>
     /// static special attack stat of the pokemon
     /// </summary>
     public int staticspatk = 1;
     /// <summary>
     /// special defense stat of the pokemon
     /// </summary>
     public int spdef = 1;
     /// <summary>
     /// static special defense stat of the pokemon
     /// </summary>
     public int staticspdef = 1;
     /// <summary>
     /// speed stat of the pokemon
     /// </summary>
     public int speed = 1;
     /// <summary>
     /// static speed staf of the pokemon
     /// </summary>
     public int staticspeed = 1;
 
     /// <summary>
     /// evasiness of the pokmeon (abilijty to dodge)
     /// </summary>
     public int evasiness = 1;
     /// <summary>
     /// accuracy of the pokemon (ability to hit)
     /// </summary>
     public int accuracy = 1;
 
     /// <summary>
     /// Type of the pokemon
     /// </summary>
     public int type1 = 0;
     /// <summary>
     /// second type of the pokemon
     /// </summary>
     public int type2 = 0;
 }

and for testing I have made this:

     public Pokemon[] party = new Pokemon[5];
 
     void Start()
     {
         audio = GetComponent<AudioSource>();
         party[0] = new Pokemon();
         
         
         party[0].level = 5;
         party[0].nickname = "";
         party[0].hp = 10;
         party[0].pokedexNumber = 160;
         party[0].name = Settings.pokemonNames[party[0].pokedexNumber];
 }

The settings class has the following:

 public static string[] pokemonNames = 
 {    "null",
 "Bulbasaur",
 "Ivysaur",
 "Venusaur",
 "Charmander",

etc..

Now do I do the same for the type or is there a way better way to create this type of thing?

My idea about the typing:

         party[0].type1 = Settings.getType1(party[0].pokedexNumber);
         party[0].type2 = Settings.getType2(party[0].pokedexNumber);

and where it gets it from:

     public static int 
         EMPTY = 0,
         NORMAL = 1, FIRE = 2, FIGHTING = 3, WATER = 4, FLYING = 5, GRASS = 6,
         POISON = 7, ELECTRIC = 8, GROUND = 9, PSYCHIC = 10,
         ROCK = 11, ICE = 12, BUG = 13, DRAGON = 14, GHOST = 15, DARK = 16, STEEL = 17, FAIRY = 18;

 public static int getType1(int pokemon)
 {
     switch (pokemon)
     {
         case 0:
             return NORMAL;
             break;
         case 1:
             return GRASS;
             break;
         default:
             return 0;
             break;
     }
 }
 public static int getType2(int pokemon)
 {
     switch (pokemon)
     {
         case 0:
             return NORMAL;
             break;
         case 1:
             return POISON;
             break;
         default:
             return 0;
             break;
     }
 }



Thanks for reading, looking forward to tips and tricks :)!

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 Bioinformatizer · Jul 05, 2015 at 01:06 PM

One suggestion would be to convert your "public static int" from where your script gets its type to an ENUM. Those do exactly what you are looking for them to do with the static int and learning about them may help with a game structured like this. Another thing that may or may not help would be to have an additional bool variable for multi type then an if statement for the type "public static int getType2(int pokemon)" to check whether there where two types to begin with.

Comment
Add comment · Show 1 · 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 Jan_Julius · Jul 05, 2015 at 02:20 PM 0
Share

Okay interesting I'll try out a few thigns with enums thanks for your reply.

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

23 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

Related Questions

Multiple Cars not working 1 Answer

Help using LitJson 1 Answer

Listing multiple objects 2 Answers

Index Out of Range Exception - can't figure it out 1 Answer

Is it possible to make sealed overridden MonoBehaviour method. 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