Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 JorgenFreeman · Oct 31, 2012 at 12:49 PM · listcolourc

Changing the colour of all of the gameobjects in a list C#

I have a list of cities the player owns which changes regularly and I need to change the colour of all of the cities in the list to green. How do I go about 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

Answer by Hannibalov · Oct 31, 2012 at 12:54 PM

Find all gameObjects you need (there are various ways to do that), and then:

 foreach(GameObject c in cities)
 city.renderer.material.color = Color.green;

(Assuming cities is the list of cities you need to change the color to)

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 JorgenFreeman · Oct 31, 2012 at 02:26 PM 0
Share

Thanks for the quick reply! I have another issue before I can see if it works, I've basically got a base city class which the other city scripts inherit from and in this i declare the list. I'm trying to add the cities to the list from the inheriting script, but it's not editing the list in the base class - each city is making its own list and the lists aren't interacting.

How do I edit the list in the base class from the inheriting classes?

avatar image Hannibalov · Oct 31, 2012 at 02:30 PM 0
Share

Sorry, but can you rephrase that? When it comes to inheritance, it better be cristal clear, and I didn't get it 100%.

avatar image JorgenFreeman · Oct 31, 2012 at 03:12 PM 0
Share

I have a base city class attached to an empty, and then different scripts which are attached to the cities themselves. The scripts on the cities inherit from the base city class.

avatar image Hannibalov · Oct 31, 2012 at 03:21 PM 0
Share

Ok, then either you don't fully understand how inheritance works or I still didn't understand what's happening.

In case it's the first one, here's a quick explanation: Classes do inherit from other classes, but objects don't, they are different instances. So either you create a singleton class (a single instance) that holds the list of cities, or you make a method to find all cities on demand and you get rid of the list.

But bear in $$anonymous$$d that as far I understood, you are creating multiple instances of objects and you can't expect these objects to share information because their class inherits from the same base class. That's just not how it works.

avatar image JorgenFreeman · Oct 31, 2012 at 04:14 PM 0
Share

I know they don't share information, I'm asking how to make them share information

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.

Follow this Question

Answers Answers and Comments

10 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

Related Questions

A node in a childnode? 1 Answer

Difference between List<> and Array[] 2 Answers

combine words of different scenes in a list or array; have each word link to a page 3 Answers

Force typcasting of member objects in a List? (Boo) 1 Answer

Problem with targeting system 0 Answers


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