How can I change the value of the alpha channel at run time. The one that is in the slider. Right now A = 247.
This code is wrong:
this.renderer.material.color.a = count;
it changes the alpha of something else.
How can I change the value of the alpha channel at run time. The one that is in the slider. Right now A = 247.
This code is wrong:
this.renderer.material.color.a = count;
it changes the alpha of something else.
Color.a = Value between 0 and 1 using for alpha color
Try this
using UnityEngine;
using System.Collections;
public class Example : MonoBehaviour
{
public GameObject myGameObj;
public Color myColor;
void Start()
{
myColor = myGameObj.renderer.material.color;
}
void Update()
{
if(Input.GetKeyDown(KeyCode.A))
{
myColor.a = (247f/255f); // for alpha color 247
myGameObj.renderer.material.color = myColor;
}
if(Input.GetKeyDown(KeyCode.B))
{
myColor.a = (200f/255f); // for alpha color 200
myGameObj.renderer.material.color = myColor;
}
}
}
It might be revealing what “something else” it is changing. You could be much more descriptive about your problem. Using C# maybe something like this:
Color newColor = renderer.material.color;
newColor.a -= 0.1f;//this can change it over time
renderer.material.color = newColor;