- Home /
Access unity Image.Alpha? Assets/Scripts/GUI/Missionupdate.cs(17,23): error CS1061: Type `UnityEngine.UI.Image' does not contain a definition for `Alpha' and no extension method `Alpha' of type `UnityEngine.UI.Image'
Gday Gang trying to access the Alpha property to gui image sop i can make it fade out over time for my mission update effect,
Assets/Scripts/GUI/Missionupdate.cs(17,23): error CS1061: Type UnityEngine.UI.Image' does not contain a definition for
Alpha' and no extension method Alpha' of type
UnityEngine.UI.Image' could be found (are you missing a using directive or an assembly reference?)
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Missionupdate : MonoBehaviour {
public Image image;
public float FadeTime = 12f;
void Start() {
image = GetComponent<Image>();
}
void Update (){
image.Alpha -= 1 * FadeTime * Time.deltaTime;
}
}
Answer by phxvyper · Mar 31, 2016 at 08:02 PM
the Image class doesn't have a member Alpha. It does, however, have a member Color.
Example:
Color newColor = image.Color;
newColor.a = 0.5f; // The alpha is now 50%. (or 256 / 2)
image.Color = newColor;
Keep in mind that in C#, image.Color works similarly to, say, transform.position. You cannot directly change the values of image.Color without resetting the entire value, like I did in the above code.
Your answer
Follow this Question
Related Questions
Why when i color the 4 walls or getting all the blocks from the 4 walls they are not equal ? 0 Answers
If-else statement executing incorrectly in foreach loop,why? 0 Answers
TouchControls/MouseInput HELP PLEASE 0 Answers
Performance: Multiple asset references vs. One public asset reference 2 Answers
What is a target component? 1 Answer