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 Trailus · Apr 22, 2013 at 08:25 PM · noobcolorpicker

how do you switch between colors on the same gameobject?

Hey I'm new to unity and currently in school for programming. Right now were doing a project where we make a cube and with the press of certain keys make it change to select colors. I have the code for setting the color and for targeting the gameobject. but what i can't figure out is how to make it change color when i press the button for a different color. help would be appreciated... or even just some advice. i searched online but all my searches just dance around the subject


Edit : my code so far

 var target : GameObject;
 var pick;
 
 function Start () {
 
  switch (pick){
 
  case 'a': target.renderer.material.color = Color.blue;
   break;
 
   case 's': target.renderer.material.color = Color.cyan;
   break;
 
   case 'd': target.renderer.material.color = Color.green;
   break;
 
   case 'f': target.renderer.material.color = Color.yellow;
   break;
 
   case 'q': target.renderer.material.color = Color.red;
   break;
 
   case 'w': target.renderer.material.color = Color.magenta;
   break;
 
   case 'e': target.renderer.material.color = Color.grey;
   break;
 
   case 'r': target.renderer.material.color = Color.white;
   break;
  }
 }
 
 function Update () {
 
  var pick = Input;
  
 }return pick;
Comment
Add comment · Show 1
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 AlucardJay · Apr 22, 2013 at 08:28 PM 0
Share

If you submit your code when asking a question, we can see what you are trying to do and help from there.

  • http://forum.unity3d.com/

  • http://answers.unity3d.com/page/newuser.html

  • http://video.unity3d.com/video/7720450/tutorials-using-unity-answers

1 Reply

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

Answer by AlucardJay · Apr 22, 2013 at 08:33 PM

 var currentColour : int = 0;
 var maxColours : int = 4;
 
 function Update()
 {
     if ( Input.GetMouseButtonDown(0) )
     {
         currentColour ++;

         if ( currentColour >= maxColours  )
         {
             currentColour = 0;
         }
         
         switch( currentColour )
         {
             case 0 : 
                 // change colour to the first colour
             break; 
 
             case 1 : 
                 // change colour to the second colour
             break; 
 
             case 2 : 
                 // change colour to the third colour
             break; 
 
             case 3 : 
                 // change colour to the fourth colour
             break; 
         }
     }
 }

Does this mean I just did your homework?

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 Trailus · Apr 22, 2013 at 08:37 PM 0
Share

not necessarily.... i'm mostly working on getting it to sayif i press a it will turnt he cube blue and if i then hit w it will change to red... i think the main issue i been having is getting the system to read the input of the key

avatar image AlucardJay · Apr 22, 2013 at 08:41 PM 0
Share
  • http://docs.unity3d.com/Documentation/ScriptReference/Input.html

  • http://docs.unity3d.com/Documentation/ScriptReference/Input.Get$$anonymous$$eyDown.html

  • http://docs.unity3d.com/Documentation/$$anonymous$$anual/Input.html

  • http://docs.unity3d.com/Documentation/ScriptReference/Input.GetButtonDown.html

avatar image AlucardJay · Apr 22, 2013 at 08:44 PM 0
Share

Actually, your code is a mess. Exa$$anonymous$$e the logic, read it as a computer would.

  • Start happens only once (without going into detail, keeping it simple)

  • var pick = Input; : see my above post

  • }return pick; : you cannot execute commands outside of functions

So, structure it just like my example. Get your input, then switch on that input in the Update function

avatar image Trailus · Apr 22, 2013 at 09:15 PM 0
Share

ALRIGHT GOT IT thanx for your help.

avatar image Trailus · Apr 22, 2013 at 09:21 PM 0
Share

and rest assured you didnt do my home work for me but you did point me in the right direction

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

12 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Random number that doesn't repeat. (javascript) 3 Answers

Alarm lights not changing 1 Answer

Where can I learn about javascript?? 3 Answers

Can someone help me fix my Javascript for Flickering Light? 6 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