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 /
avatar image
0
Question by kazmerkaya · Mar 28, 2016 at 12:52 AM · playerprefssave datacolors

Save Object Material Color ??

I change the color of the material objects , but not save . i am use c# and change color of UI Button.

please help me...

 using UnityEngine;
     using System.Collections;
     using UnityEngine.UI;
     
     public class ColorSelector : MonoBehaviour {
     
             public GameObject vehicle01;
     
             public static Vector4 hexColor(float r, float g, float b, float a){
                     Vector4 color = new Vector4(r/255, g/255, b/255, a/255);
                     return color;
             }
     
             public void red () {
     
             vehicle01.GetComponent<Renderer>().sharedMaterial.color = new Color(1, 0, 0, 1);
             }
     
             public void blue () {
     
                     vehicle01.GetComponent<Renderer>().sharedMaterial.color = new Color(0, 0, 1, 1);
             }
     
             public void black () {
     
                     vehicle01.GetComponent<Renderer>().sharedMaterial.color = new Color(0, 0, 0, 0);
             }
     
             public void cyan () {
     
                     vehicle01.GetComponent<Renderer>().sharedMaterial.color = new Color(0, 1, 1, 1);
             }
     
             public void gray () {
     
                     vehicle01.GetComponent<Renderer>().sharedMaterial.color = new Color(0.5f, 0.5f, 0.5f, 1);
             }
     
             public void green () {
     
                     vehicle01.GetComponent<Renderer>().sharedMaterial.color = new Color(0, 1, 0, 1);
             }
     
             public void magenta () {
     
                     vehicle01.GetComponent<Renderer>().sharedMaterial.color = new Color(1, 0, 1, 1);
             }
     
             public void white () {
     
                     vehicle01.GetComponent<Renderer>().sharedMaterial.color = new Color(1, 1, 1, 1);
             }
     
             public void yellow () {
     
                     vehicle01.GetComponent<Renderer>().sharedMaterial.color = hexColor(255,215,0,255);
             }
     
             public void pink () {
     
                     vehicle01.GetComponent<Renderer>().sharedMaterial.color = hexColor(255,105,180,255);
             }
     
             public void teal () {
     
                     vehicle01.GetComponent<Renderer>().sharedMaterial.color = hexColor(0,128,128,255);
             }
     
             public void purple () {
     
                     vehicle01.GetComponent<Renderer>().sharedMaterial.color = hexColor(128,0,128,255);
             }
     
             public void silver () {
     
                     vehicle01.GetComponent<Renderer>().sharedMaterial.color = hexColor(188,198,204,255);
             }
     
             public void apricot () {
     
                     vehicle01.GetComponent<Renderer>().sharedMaterial.color = hexColor(251, 206, 177,255);
             }
     
             public void smokegray () {
     
                     vehicle01.GetComponent<Renderer>().sharedMaterial.color = hexColor(112,140,152,255);
             }
     
             public void orange () {
     
                     vehicle01.GetComponent<Renderer>().sharedMaterial.color = hexColor(237,135,45,255);
             }
     }
 
 
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 aditya · Mar 28, 2016 at 11:36 AM

use this : http://docs.unity3d.com/ScriptReference/Material-color.html

Comment
Add comment · Show 4 · 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 kazmerkaya · Mar 28, 2016 at 02:00 PM 0
Share

Thank you , but unfortunately I do not know how I will register according to my code??

avatar image aditya kazmerkaya · Mar 29, 2016 at 05:39 AM 0
Share

ui doesnot have any Renderer component on it, so use this

vehicle01.GetComponent<SpriteRenderer>().color = hexColor(255,105,180,255);

avatar image kazmerkaya · Mar 29, 2016 at 08:25 AM 0
Share

Okay. $$anonymous$$y project Android project. I am changed color my code now. $$anonymous$$ake build and change the color but does not even save on the phone. How can I save as a method playerprefs c#. thank you.

avatar image aditya kazmerkaya · Apr 01, 2016 at 05:05 AM 0
Share

try saving it in xml files, in the code below i will show you how to create a xml file and there are lot of tutorials online which will $$anonymous$$ch you how to read and write xml files

 using UnityEngine;
 using System.Collections;
 using System.IO;
 
 public class writeX$$anonymous$$L : $$anonymous$$onoBehaviour {
     void Start () {
         File.Create (Application.persistentDataPath + @"/testX$$anonymous$$L.xml").Dispose ();
         using(StreamWriter wrtr = new StreamWriter(Application.persistentDataPath + @"/testX$$anonymous$$L.xml")){
             wrtr.WriteLine ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
             wrtr.WriteLine ("<rootTag>");
             wrtr.WriteLine ("</rootTag>");
         }
     }
 }


Use This toHow to Read X$$anonymous$$L Files Use This toHow to Write X$$anonymous$$L Files

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

Unity problem when i convert playerprefs save to the standard file io save 0 Answers

PlayerPrefs to save setActive state 2 Answers

PlayerPrefs saving, but not loading some values 2 Answers

Save.dataPath Android Location 0 Answers

How can I save my game data 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