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 sourav13 · Jun 07, 2016 at 05:18 AM · material color

Make changes to Sprites/Default Material and not saving this change in prefabs.

I have a background which has a sprite renderer with Sprites /Default Material on it , and i change the materials color in the update function and after the game ends and i press playagain the material already has that color applied to it , i want that color to be reset back to the one which as at the start.

[EDIT]:

@saud_ahmed020 Here is the little code snippet .

I have simple Material and i changed it's color in default . like

Background.GetComponent ().material.color = Color.Lerp (new Color (0.20f, 0.19f, 0.19f, 1), new Color (0.78f, 0.11f, 0.11f, 1), time / 4);

and i also have game setup function which i call in the start and at replay . that function contains the following code .

Background.GetComponent ().material.color = Color.black;

But the the color doesn't change back to normal after the first play , i mean the line doesn't work when i press replay , i have debugged the code , the code at this breakpoint is reachable but is not having any affect , really confused.

Comment
Add comment · Show 4
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 saud_ahmed020 · Jun 07, 2016 at 06:15 AM 0
Share

@sourav13 Can you share your code ??

avatar image sourav13 · Jun 07, 2016 at 07:51 AM 0
Share

@saud_ahmed020 I have shared the code in the question edit.

avatar image saud_ahmed020 · Jun 07, 2016 at 08:58 AM 0
Share

@sourav13 I have tested it. It works but I think you are doing something different that you are saying.

 using UnityEngine;
 using System.Collections;
 
 public class Test : $$anonymous$$onoBehaviour
 {
 
     void Start(){
         GetComponent<SpriteRenderer>().material.color = Color.Lerp (new Color (0.20f, 0.19f, 0.19f, 1), 
                                                                     new Color (0.78f, 0.11f, 0.11f, 1), 1);
         Invoke("ChangeColor",1);
     }
 
     void ChangeColor()
     {
         GetComponent<SpriteRenderer>().material.color = Color.black;
     }
 
 }

screen-shot-2016-06-07-at-15613-pm.png (313.2 kB)
avatar image sourav13 · Jun 07, 2016 at 09:40 AM 0
Share

You have done quite the reverse of $$anonymous$$e want the Color to be black at the start and than you have tried invoke (here i'm Lerping in update , that's ok ) and than i have condition in update which stops the script and another function in which i'm resetting the color and turning back the script on . ( this function runs on a button click ) .

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by tanoshimi · Jun 07, 2016 at 06:27 AM

At a guess, you're modifying sharedMaterial.color, which will modify the asset on disk and persist even after playmode stops. To modify just the instance of the material attached to the object during runtime, change material.color instead.

Comment
Add comment · Show 1 · 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 sourav13 · Jun 07, 2016 at 06:55 AM 0
Share

@tonoshimi I have updated the question with little code , I'm using material.color not shared$$anonymous$$aterial.color.

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

44 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

Related Questions

Colors Seem all wrong when I set them in RGB 2 Answers

Changing material.color does not work 1 Answer

Adjust tint color of particles/additive? 2 Answers

Change the material of ONLY a specific body part of an avatar 1 Answer

Material turns blue when changing the emission color smoothly 0 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