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 bassboy · Mar 23, 2014 at 09:19 PM · gameobjectgame

Populate game objects from a list?? (C#)

So I'm fairly new to unity and programming but my goal is to take the variables from my list items here:

     List<Cards> cardValue = new List<Cards> ();

     cardValue.Add (new Cards ("One", 1, 1, 1, 1));
     cardValue.Add (new Cards ("Two", 2,2,2,2));
     cardValue.Add (new Cards ("Three", 3,3,3,3));
     cardValue.Add (new Cards ("Four", 4,4,4,4));
     cardValue.Add (new Cards ("Five", 5,5,5,5));
     cardValue.Add (new Cards ("Six", 6,6,6,6));
     cardValue.Add (new Cards ("Seven", 7,7,7,7));
     cardValue.Add (new Cards ("Eight", 8,8,8,8));
     cardValue.Add (new Cards ("Nine", 9,9,9,9));
     cardValue.Add (new Cards ("Ten", 10, 10, 10, 10));

And have these values pass onto "cards" in my scene but I am unsure how to go about doing this. In my scene I simply have 10 game objects all listed as Card1, Card2, etc up to Card10. I want to be able to pass "one" onto Card1 along with the values in that line, "Two" onto Card2 and it's values, Etc.

Any solution or even a nudge in the right direction would be so helpful :(

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 taylank · Mar 24, 2014 at 01:15 AM

You probably want to have a single "Card" prefab, which you can instantiate as needed from another script that's on a GameManager sort of gameObject. On this Card prefab, you can have a behaviour that's called something like CardScript.cs and inside that, you can have public variables for whatever data you want your cards to have: i.e. string cardName; int cardValue; etc.

So you'd do something like:

 CardScript cs = Instantiate("Card", position, rotation) as CardScript;
 //and access its variables via cs
 cs.cardName = cardValue[0].name;
Comment
Add comment · 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

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

21 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

Related Questions

melee system script problem, what did i do wrong or what to do next? 0 Answers

C# Rotate GameObjects Regardless of List Size 2 Answers

expecting (, found 'OnConnectedToServer'. 0 Answers

Explosion script question 0 Answers

C# Change Script Help 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