- Home /
Problem with color c#
I`ve made a simple code, that changes tint color during the time, and it works fine when line that changes color is like that: renderer.material.SetColor("_TintColor",Color.magenta); But it works not right if i change color like this:
public class RenderColorTest : MonoBehaviour {
public float Timer = 1f;
Color colorBlue;
// Use this for initialization
void Start ()
{
colorBlue.r = 0;
colorBlue.g = 105;
colorBlue.b = 255;
colorBlue.a = 128;
}
// Update is called once per frame
void Update ()
{
Timer -= Time.deltaTime;
if(Timer < 0)
renderer.material.SetColor("_TintColor",colorBlue);
}
}
Thanks for any help!
hm how about something like that in line 18
renderer.material.SetColor("_TintColor", new Color(0f, 105f, 255f, 128f));
What $$anonymous$$exallon suggested could work. You can also do it by setting the color in start as :
colorBlue = new Color(0f, 105f, 255f, 128f);
and just going with what you have in your code. C# doesn't allow for individual members of Color to be set separately.
Answer by electricsauce · Jun 02, 2013 at 11:50 PM
This works for me:
using UnityEngine;
using System.Collections;
public class Colorchanger : MonoBehaviour {
public float Timer = 10f;
Color colorBlue = new Color(0, 0, 0, 0);
// Use this for initialization
void Start ()
{
colorBlue.r = 0;
colorBlue.g = 105.0f;
colorBlue.b = 255.0f;
colorBlue.a = 128.0f;
}
// Update is called once per frame
void Update ()
{
Timer -= Time.deltaTime;
if(Timer < 0)
//what I used to test
// renderer.material.SetColor("_Color",colorBlue);
renderer.material.SetColor("_TintColor",colorBlue);
}
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Blend into next color instead of jumping to next color 1 Answer
Creating Loading Bar For web Player 1 Answer
play sound on click 2 Answers