- Home /
Question by
Acurx · Sep 21, 2015 at 07:52 PM ·
2dspritetransparencyopacity
How to change sprite opacity during runtime
can i change a sprite opacity from 0% to 100% during runtime after 2 sec of starting the game ?
Comment
Answer by vintar · Sep 21, 2015 at 08:00 PM
maybe something like this:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class ChangeAlpha : MonoBehaviour
{
Image image;
IEnumerator Start()
{
yield return new WaitForSeconds(2);
Color c = image.color;
c.a = 1;
image.color = c;
}
}
Didn't work They are both the same error btw , i just named them error 1 and error 2
error-1.png
(139.1 kB)
error-2.png
(16.7 kB)
Answer by sonu124 · Sep 22, 2015 at 07:20 AM
You can change the Image opacity like this way...........
public class opacity : MonoBehaviour {
public Image img;
// Use this for initialization
void Start ()
{
StartCoroutine ("Wait");
}
IEnumerator Wait()
{
yield return new WaitForSeconds (2.0f);
img.color = new Color (1.0f,1.0f,1.0f,1.0f);
StopCoroutine ("Wait");
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612034541im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Making transparent sprite render as quad 1 Answer
How to render a sprite in the opaque pass 0 Answers
Can I change the transparency of a Sprite only in the area where it is overlapped by another one? 0 Answers
Light and 2D Sprite overlapping issue 1 Answer
Transparency on overlapping 2D objects 0 Answers