Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Headrush95 · Jul 06, 2020 at 04:38 PM · scripting beginnermaterial coloremissionlerping

lerp between emission colours

hey guys, so i have been trying all day to do this and can't find anything on it anywhere, so i know how to lerp between colors for the main colour of a material, and i know how to set colours in C#, but ive been trying to lerp the emission colour from orange to red, and nothing seems to be working, here is my code;

please help me out here guys, i know i'm gonna look dumb when it turns out to be super simple :').

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class GemGlow : MonoBehaviour
 {
 public Material Mat;
 
 Vector4 red;
 
 Vector4 orange;
 
   
 
 void Start() {
 
 orange =  new Vector4(1.320755f, 0.5346785f,0.2928088f,0.8182f);
 
 red = new Vector4(0.858f, 0f,0f,0.8182f);
 
     var Mat = GetComponent<Renderer>().material;
 
     Mat.EnableKeyword("_EMISSION");
 
 
 
 
 
 }
 
 void Update() {
 
 Mat.SetColor("_EmissionColor",(Color.Lerp(orange, red, 1)));
 
  
  
 
 
  
 
 
 
     
 }
 }
 
 
 
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

2 Replies

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

Answer by Headrush95 · Jul 19, 2020 at 12:12 AM

btw i figured this out for anyone struggling,

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class GemGlowOrange : MonoBehaviour
 {
 public Material Mat;
 
 Color Red;
 
 Color red;
 
 Color lightpurple;
 
 Color orange;
 
 public bool isInDanger = false;
 
 
 float startTime;
 
 public float speed = 1.0f;
 
 
 
 void Start() {
 
     startTime = Time.time; // time since game started
 
 orange =  new Color(1.320755f, 0.5346785f,0.2928088f,1f); // making my colours RGBA
 
 Red = new Color(0.858f, 0f,0f,1f);
 
 lightpurple = new Color(1.320755f,0.2973427f,0.8263685f,1f);
 
 
     var Mat = GetComponent<Renderer>().sharedMaterial; // making a reference to the material so we can enable the emission keyword if you do not want this to affect every object using this
     //material then use "Getcomponent<Renderer>().material" the same goes with setting the color as you can see further down.
 
  
 
     Mat.EnableKeyword("_EMISSION"); // this is making sure this shader has the emission keyword enabled.
   
 
 
 
 
 
 }
 
 void Update() {
 
 
 
 
 
 
 
 
     if(!isInDanger){
 
     float frac = (Mathf.Sin(Time.time - startTime) * speed);
 
 GetComponent<Renderer>().sharedMaterial.SetColor("_EmissiveColor", Color.Lerp(lightpurple, orange, frac)); // getting the same material over and over again each frame and updating it's
 // emission colour
 
 
 
 
          
 
     } else if (isInDanger) {
          float frac = (Mathf.Sin(Time.time - startTime) * speed);
 
 GetComponent<Renderer>().sharedMaterial.SetColor("_EmissiveColor", Color.Lerp(Red, orange, frac)); // if it is in danger then it will alternate between red and orange.
 
    
 }
 
  
  
 
 
  
 
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 dim_wes · Sep 25, 2021 at 09:12 PM 0
Share

For me, the code didn't work until I changed "_EmissiveColor" to "_EmissionColor" in line 63 and 75 - I'm not sure, if this was a typo or both things exist, but maybe this information can help someone :)

avatar image
0

Answer by ThugsInMugs · Jul 06, 2020 at 04:52 PM

I cant test right now but wouldn't it just be Vector4.Lerp(Color 1 values, color 2 values, speed / Time.deltaTime); ? Lerping is for numerical values.

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

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

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

Getting value of material and applying it to another material through code 1 Answer

material.SetColor ("_EmissionColor", Color.white) 1 Answer

Acces to a material issue 1 Answer

Unity 5.6: Shader Broken and Showing Up Black 0 Answers

Emissive color on material scripting 2 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