Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by hvd · Oct 22, 2015 at 04:31 PM · listobjectsproperties

saving objects with properties in a c# list

hi guys , i'm trying to develop a game in which you'r driving a car convoy and adding members to the convoy . I want to add the new convoy members in a list and want to add properties to them like health points, armor etc. , how can i manage that and what type of list is needed for this?

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 Statement · Oct 22, 2015 at 05:11 PM

Create a class to define your ConvoyMember properties.
Use List to easily add and remove members.

 using UnityEngine;

 public class ConvoyMember : MonoBehaviour
 {
     public string firstName = "John";
     public string lastName = "Doe";
     public string address = "Unity Help Room";
     public Sprite icon = null;
     public float health = 100;
     public float armor = 100;
     
     public override string ToString()
     {
         return firstName + " " + lastName + " from " + address;
     }
 }

Keep your members in your Convoy for instance.

 using UnityEngine;
 using System.Collections.Generic;

 public class Convoy : MonoBehaviour
 {
     public List<ConvoyMember> members = new List<ConvoyMember>();
 
     public void LogAllMembers()
     {
         foreach (var member in members)
             print(member);
     }
 }


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 hvd · Oct 22, 2015 at 05:36 PM 0
Share

Ok thx , and if i want different members with different properties , do i need a second class and list?

And a second question , can i get these members to follow each other with a head controlling the movement?

avatar image Statement hvd · Oct 22, 2015 at 05:54 PM 0
Share

Yes, you can subclass from Convoy$$anonymous$$ember to create specialized Convoy$$anonymous$$ember types, but think about what you actually are going to add and how they are going to be used. You could also add more components to the game object that Convoy$$anonymous$$ember sits on.

Yes, you can get them to follow each other. How to get them to follow each other is a separate question that should have it's own thread on this site. Solutions could range from path finding to boid behaviour to generating motion commands that should be executed in order. Figure out what is most important for you at this point and focus on that first.

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

31 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I have custom inspector variables in an object list? 0 Answers

Hide or show objects in a list not working correctly 1 Answer

Add object of specific width to a List 0 Answers

Add inactive objects to list 0 Answers

Add object of specific width to a List 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