Question by
Busil · Feb 20, 2016 at 11:28 AM ·
getcomponent
How to GetComponent Image, color,alpha.
Hi, I want to modify alpha in Color. How can I access it through the C# script?
przechwytywanie.png
(30.5 kB)
Comment
Answer by arvindiitkgp · Feb 20, 2016 at 04:37 PM
First of all you need to use namespace UnityEngine.UI then assign Image and get its color, alpha etc...
Example : Attach this script to your Image gameobject :
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Test : MonoBehaviour {
public Image image;
public Color imageColorToBeUsed = Color.green;
public float currentImageColorAlpha = 0.5f;
// Use this for initialization
void Start () {
image = GetComponent<Image> ();
//Get the alpha value of Color
currentImageColorAlpha = image.color.a;
//Assign Color
image.color = imageColorToBeUsed;
}
// Update is called once per frame
void Update () {
}
}
Hope this will help :)
Answer by Lfs1992 · May 18, 2017 at 04:09 PM
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Test : MonoBehaviour {
public Image myimage;
void Update () {
myImage.CrossFadeAlpha(1.0f, 1.0f, true);//CrossFadeAlpha(Alpha, Time, Ignore time scale)
}
}
Your answer
Follow this Question
Related Questions
Javascript GetComponent not work! 0 Answers
ERROR CS0119 C# GetComponent< > 1 Answer
Best way to reach a component or script's function? 1 Answer
Semicolon expected before end of line 0 Answers