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 SeyedMahdi · Jul 13, 2014 at 03:49 PM · buttoncolor change

Object color change

Hello

I am trying to change my game object color through script, I have defined my game object and my buttons as game objects, but when I click on them, color of game object does not change.

public class ChangeColor : MonoBehaviour {

 // Define C911B game object
 private GameObject C911B = new GameObject();

 // Define buttons
 private GameObject turnred = new GameObject();
 private GameObject turnblack = new GameObject ();
 private GameObject turnwhite = new GameObject ();
 private GameObject turnyellow = new GameObject ();

 // Use this for initialization
 void Start () {
     GameObject.Find ("911B").renderer.enabled = true;
     GameObject.Find ("turn-red").renderer.enabled = true;
     GameObject.Find ("turn-black").renderer.enabled = true;
     GameObject.Find ("turn-white").renderer.enabled = true;
     GameObject.Find ("turn-yellow").renderer.enabled = true;

     C911B = GameObject.Find ("911B");
     turnred = GameObject.Find ("turn-red");
     turnblack = GameObject.Find ("turn-black");
     turnwhite = GameObject.Find ("turn-whit");
     turnyellow = GameObject.Find ("turn-yellow");
 
 }
 
 // Update is called once per frame
 //void Update () {
 //
 //}

 void OnMouseClick ()
 {
     if (turnred) {
                     C911B.renderer.material.color = new Color (232, 0, 0, 255);
             } else if (turnblack) {
                     C911B.renderer.material.color = new Color (0, 0, 0, 255);
             } else if (turnwhite) {
                     C911B.renderer.material.color = new Color (184, 184, 184, 255);
             } else if (turnyellow) {
                     C911B.renderer.material.color = new Color (201, 187, 0, 255);
             }
 }

}

Comment
Add comment · Show 6
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 tanoshimi · Jul 13, 2014 at 03:55 PM 0
Share

turnred is a gameobject, but you're treating it like a Boolean:

 if (turnred) {
avatar image Lo0NuhtiK · Jul 13, 2014 at 04:03 PM 0
Share

@Seyed$$anonymous$$ahdi : Why did you ask this again? http://answers.unity3d.com/questions/746892/cs0029-convert-type.html

avatar image YoungDeveloper · Jul 13, 2014 at 04:07 PM 0
Share

@Lo0Nuhti$$anonymous$$ He probably didn't know asking questions with that reputation requires approval.

avatar image Lo0NuhtiK · Jul 13, 2014 at 04:10 PM 1
Share

Nah... the other question has been posted for about a day, and this question's content has the changes to the script that someone else showed in the other topic ;) ..tags are all "help help help" also, so Seyed is just being impatient lol

avatar image SeyedMahdi · Jul 13, 2014 at 04:45 PM 0
Share

Thank you for comments, because I dont get working answer in one post, I post it with changes to see if other people help @Lo0Nuhtik and @YoungDeveloper

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

CS0029 convert type 1 Answer

Change color of object 1 Answer

How can I draw a line in Unity with mouse ....? 1 Answer

I made a better shader how do i fix[add _Shadow Strength]help???>Sorry that im asking for to much 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