• 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 Borzi · Oct 20, 2013 at 01:55 PM · listclassintparameter

Edit each Parameter Class on Function

Hey, I am trying to make it so that 1 is added to "Row" each time the function "ConvertParamsToClass" is called, but I don't know how to do that. Can someone help me?

 //Variables:
 
 public List<KillFeedInfo> KFI = new List<KillFeedInfo>();
 
 private void ConvertParamsToClass(string Killer, string Gun, string Killed)
     {
     int Row = 0;
     Debug.Log ("Converting Params To Class");
     KillFeedInfo k = new KillFeedInfo(Killer, Gun, Killed, Row);
     KFI.Add(k);
     foreach (KillFeedInfo k in KFI)
         {
         k.Row ++;
         }
     Debug.Log ("Added k");
     }
 }
 
 [System.Serializable]
 public class KillFeedInfo
 {
     public int Row;
     public string Killer;
     public string Gun;
     public string Killed;
     
     public KillFeedInfo(string K, string G, string V, int R)
     {
         Killer = K;
         Gun = G;
         Killed = V;
         Row = R;
     }
 }
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
Best Answer

Answer by meat5000 · Oct 20, 2013 at 02:00 PM

Create your function inside your class. It should then be able to access the variable and you won't need to declare it again within the function.

Alternatively, change it from void function and add a return statement. Maybe return 1 and add that each time.

Comment
Add comment · Show 6 · 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 Borzi · Oct 20, 2013 at 02:12 PM 0
Share

Could you show an example? Because I am not really sure how to make a function in a class...I tried this but it doesnt work apparently.

 public AddRow()
     {
     Row ++;
     }
avatar image meat5000 ♦ · Oct 20, 2013 at 02:16 PM 0
Share
 Class
 {
    class variables //class wide scope
 
    function
    {
      function variables //only has scope within function
      //can access class variables here
    }
 
    another function
    {
      function variables //can't access variables of first function
      //can access class variables here
    }
 }
avatar image Borzi · Oct 20, 2013 at 02:49 PM 0
Share

How would this be applied in this example? Also: functions in this case are supposed to be voids...? Because I am using C#

avatar image meat5000 ♦ · Oct 20, 2013 at 02:54 PM 0
Share

Its just pseudocode to show you how to structure your class and functions.

Basically, the structure I show you is the simplest way to share variables between functions allowing you to modify them without having to pass any arguments at all.

avatar image Borzi · Oct 20, 2013 at 04:01 PM 0
Share

Yes, I tried applying it but for some reason it doesn't work. I have no idea how to add the function from this example, maybe I could if you would show me some context.

Show more comments

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

16 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

Related Questions

Generic List No Sense Problem 1 Answer

A node in a childnode? 1 Answer

Saving a list from a class containing gamobjects 0 Answers

Can't call derived class function from list of base class. Ideas? 1 Answer

Need my function to work with different lists of different values (classes) 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