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 fazraz · Dec 09, 2015 at 01:24 AM · 2dinstantiateprefabcolor

Newly Instantiated Prefabs Not Changing Colour

I have a prefab called "Row1". It is a row of three squares. Two of the squares are dark blue, the middle one is light blue.

I have succeeded in turning the dark blue squares to light blue when the light blue square in the middle detects the player object.

Once this happens, the same prefab "Row1" is generated on top of the previous one. However, when the newest "Row1" prefab detects the player, the dark blue squares do not turn light blue.

The logic of my script (in natural English):

When the light blue square detects the player, find the SpriteRenderer of the first dark blue square and the second dark blue square (using GameObject.Find("darkSquare1").GetComponent() etc etc, and set their colours to light blue. Sorry for being so vague, I'm crap at explaining myself. Any help would be greatly appreciated :) Farid

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 ZefanS · Dec 09, 2015 at 08:52 AM 0
Share

If you are in fact using "GameObject.Find("darkSquare1").GetComponent() etc etc" and there are multiple "darkSqaure1"s in the scene, then you are probably only finding the first instantiated instance of "darkSquare1". You will need to do something like tag all the blue squares something and use GameObject.FindGameObjectsWithTag() and then iterate through the returned array, changing each one from dark blue to light blue. See the reference page here.

Hope this helps.

avatar image NoseKills · Dec 09, 2015 at 04:09 PM 0
Share

If you already have a 'row' prefab with those 3 objects and all rows behave the same, it would probably be easiest to attach a script to the middle square with 2 public gameobject variables in it and drag references to the left and right square to those. Now all rows know which are their 'side squares'. Since you are already able to tell which middle square the player hits, it shouldn't be hard to tell that middle square change the color of its own side squares

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by fazraz · Dec 09, 2015 at 04:25 PM

Thankyou @ZefanS and @NoseKills for your replies. I sorted the problem by serializing a public GameObject space for the dark blue squares and manually dragging them into the correct spaces in the editor. Then I saved this as the prefab.

I appreciate your help!

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

53 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 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 do I fix 2d Grid Instantiating? 1 Answer

Trying to get a 2d prefab without rigidbody to instantiate on button press, "the variable T_Bullet has not been assigned." 0 Answers

Size of instantiated clone is different from prefab 0 Answers

Spawn power ups after random amount of time 1 Answer

[2D] Set the instantiated projectile rotation from turret using generic list? There are multiple turret prefabs in the scene 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