Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question About Arrays c#

Discussion in 'Scripting' started by NikoBusiness, Jun 16, 2013.

  1. NikoBusiness

    NikoBusiness

    Joined:
    May 6, 2013
    Posts:
    289
    hey guys im working on a rpg project and i want to add character stats like damage , defence , stamina ,strength
    would it be good to make it with arrays or default variables?
     
  2. Jacksendary

    Jacksendary

    Joined:
    Jan 31, 2012
    Posts:
    408
    Why not make a class with the necessary stats and let each player (I suppose you have a player script to handle damage and combat etc.) have a single instant of the stat class?
     
  3. NikoBusiness

    NikoBusiness

    Joined:
    May 6, 2013
    Posts:
    289
    you mean to make a new script ? thats what i did in a past script that i made i just wanted to ask because i saw another one making it different than i did he was making it with arrays...
     
  4. Vanamerax

    Vanamerax

    Joined:
    Jan 12, 2012
    Posts:
    937
    depends on your needs, if all your stats will be of the same type, will have "the same function" and you want to loop through them easily, sure you can go with an array. Be sure the make a "player" script and store all your values related to your player there. Having all variables scattered around everywhere is never a good thing, keep them as local as possible
     
  5. ar0nax

    ar0nax

    Joined:
    May 26, 2011
    Posts:
    485
    go on youtube and search for burgzergarcade, he has some video-tutorials on how to make those kinds of things, he uses setters and getters to make those class specific attributes public, and you can always derive from that base class your Main Player your Enemy players, your npc's and so on...

    Give it a try, it's a good starting point :)