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 /
This question was closed Jan 09, 2017 at 06:04 AM by choustonator for the following reason:

I resolved my own issue

avatar image
0
Question by choustonator · Jan 09, 2017 at 03:30 AM · gameobjectcolor changecloned

Change color of cloned prefab objects

I am trying to create a grid of tiles and basically have them all different colors(I have an array of 4 colors to choose from). I have been working on it for hours and looking online and nothing I do seems to make it change colors from the default prefab color.

I have a script that is creating the grid and the tiles. I have tried a few different ways(both are there, one is commented out) and it always stays the same color(it isn't one in the array, it's the default color of the prefab).

void Start () { //Set colors for tiles colors[0] = new Color(242, 103, 103); //Pink colors[1] = new Color(80, 206, 196); //Blue colors[2] = new Color(147, 206, 80); //Green colors[3] = new Color(238, 174, 79); //Orange //Create the number of tiles needed GameObject[] tiles = new GameObject[numRows * numColumns]; for (int i = 1; i <= tiles.Length; i++) { tiles[i-1] = Instantiate(tilePrefab) as GameObject; tiles[i-1].transform.SetParent(gameCanvas.transform); tiles[i-1].transform.position = new Vector3 (x, y, 0f); //tiles [i - 1].GetComponent<Renderer> ().material.color = colors [3]; Renderer rend = tiles[i-1].GetComponent<Renderer>(); rend.material.color = colors [3]; x += 320; if (i % 3 == 0) { x = 300; y -= 320; } }

Everything I find online does not work or is either outdated like renderer.material.color

edit: I apologize for the code being like that, it looks organized in the text box as I edit it, but when I save, it bunches it into a paragraph

Comment
Add comment · Show 3
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 agentc0re · Jan 09, 2017 at 04:25 AM 0
Share

I just did a google search. first result man. https://docs.unity3d.com/ScriptReference/$$anonymous$$aterial.SetColor.html Hope that helps! :D

avatar image choustonator · Jan 09, 2017 at 05:15 AM 0
Share

Yeah I came across that as well and that doesn't seem to work for me either. I'm not sure what is going on at this point.

avatar image choustonator · Jan 09, 2017 at 05:22 AM 0
Share

If it helps, I am using a blank image 250x250 and changing the background color. I am using that as a prefab for my "tile object". Then in my GameScript I am creating an array of game objects and trying to change the color in a loop as I instantiate them.

1 Reply

  • Sort: 
avatar image
0

Answer by choustonator · Jan 09, 2017 at 06:03 AM

I found my mistake! After further looking online and playing around on Unity, I was using a GameObject for my image, however I needed to change it from GameObject to Image in my code and include "using UnityEngine.UI" and then tiles[i-1].color = Color.red worked.

Sorry for being a noob!

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

Follow this Question

Answers Answers and Comments

104 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 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

can you control 2 gameobject color values without having to reference both ? 0 Answers

How to click in screen and change color in my sphere? 2 Answers

OnMouseOver wont work with fps Controller 0 Answers

change color of part of plane 1 Answer

How to change the alpha of every GameObject with the same Tag ? 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