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 jtcc34 · Dec 24, 2012 at 05:52 AM · c#rpg

what am I doing wrong

I have a contoller script that my playerstats derives from. I want to put it on my main camera so that when you hit play the stats of each character here is what I am working with:

 using UnityEngine;
 using System.Collections;
 
 [RequireComponent(typeof(PlayerStats))]
 public class Controller : MonoBehaviour {
 
      public PlayerStats _jake;
 
    
 
    
 
    
 
     void Start(){
 
 
         _jake.level = 3;  
         _jake.STR = 50;
         _jake.DEX = 55;
         _jake.DEF = 50;
         _jake.vital = 100;
         _jake.Magic = 60;
         _jake.luck = 45;
         _jake.Speed = 56;
         _jake.Agility = 46;
         _jake.exp.Cur = 0;
         
     }
     
 }

note:Jake is just one of the characters that need this script there are four more party members too. here is PlayerStats:

 public class PlayerStats : Controller {
 
     public int level;
     public string name;
     public Stat Hp = new Stat();
     public Stat Mp = new Stat();
     
     
     public int STR;
     public int DEX;
     public int DEF;
     public int vital;
     public int Magic;
     public int luck;
     public int Speed;
     public int Agility;
     
     public int melee;
     public int ranged;
     public int MagA;
     public int MagD;
     public float active;
     
     public Stat exp = new Stat();
     
     public void addexp(int ex){
         
         exp.Cur += ex;
         while(exp.Cur >= exp.Max && level < 99){
             exp.Cur -= exp.Max;
             exp.Max = level *(level+1)* 500;
             level++;
             upstats();
         }
     
     }
     
     void upstats(){
         STR++;
         DEX++;
         DEF++;
         vital++;
         Magic++;
         luck++;
         Speed++;
         Agility++;
     
         
         melee =(level*7)+STR;
         ranged =(level*7)+DEX;
         DEF =(level*2)+ Agility;
         MagA =(level*7)+ Magic;
         MagD =(level*2)+ luck;
         
         active =20+((Speed * level)/1500);
         
         Hp.Max =((level * 5)+ vital)*10;
         Hp.Cur = Hp.Max;
         Mp.Max =((level * 5)+ Magic)*10;
         Mp.Cur = Mp.Max;
         
     }
     
         public class Stat{
         public int Cur;
         public int Max;
         
     }        
     
         public PlayerStats(int level,string name,int STR,int DEX,int DEF,int vital,int Magic,int luck,int speed,int Agility,int exp){
         this.level = 1;
         this.name = name;
         this.STR = STR;
         this.DEF = DEF;
         this.vital = vital;
         this.Magic = Magic;
         this.luck = luck;
         this.Speed = speed;
         this.Agility = Agility;
         addexp(exp);
     }    
     
 
 }

this script runs from the Project tab. and the controller script attaches to camera because it is for my characters all 5 of them who are in the party. I also am getting an error that says stack overflow extintion

Comment
Add comment · Show 2
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 Maulik2208 · Dec 24, 2012 at 06:48 AM 0
Share

could you please provide some more info on what you are upto....

avatar image jtcc34 · Dec 24, 2012 at 08:40 AM 0
Share

this is the other script and I want to run each character in the inpector

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by MaGuSware™ · Dec 24, 2012 at 09:43 AM

If I am understanding what it is you are wanting to do, you need to add [System.Serializable] above your PlayerStats class.

Comment
Add comment · Show 3 · 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 jtcc34 · Dec 24, 2012 at 09:55 AM 0
Share

ok thank for the tip.

avatar image jtcc34 · Dec 24, 2012 at 10:02 AM 0
Share

now unity frezze when I attach it to the camera

avatar image MaGuSware™ · Dec 24, 2012 at 10:26 AM 0
Share

That's because in the controller you have public PlayerStats _jake;

Your player stats inherit off controller. For every controller you have a new playerstats, which creates a new controller... which creates a new playerstats and so on and so on until you run out of memory.

-edit- Basically you need to make PlayerStats not inherit from Controller.

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

12 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

Related Questions

Please help with Unity Forums C# 1 Answer

SelectTarget Does not exist Current Context 1 Answer

Show Strings With Last Characters of the first Word 1 Answer

Problem with text blinking 1 Answer

Die Function Help With C# 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