Hey all, I'm trying to flash a simple PNG with an alpha on and off a few times once an event occurs, but I don't quite understand the logic. Would I need to black out the entire alpha every lets say 1 second? And since I'm basing this off of time, what function should I use? Thanks
Anytime you want to do something with timing like this, coroutines are your best friend. You can do something like this with the code: Code (csharp): IEnumerator Flash(int flashCount) { for(int i=0; i < flashCount; i++) { renderer.material.color = Color.white; yield return new WaitForSeconds(1); renderer.material.color = Color.clear; yield return new WaitForSeconds(1); } } And then you simply fire this off in your code by calling Code (csharp): StartCoroutine(Flash(YOURNUMBER));
Code (csharp): if(p1shots == 0) { GUI.Label(new Rect(halfWidth - 184, halfHeight - 27, reloadImg.width, reloadImg.height), reloadImg); } At the moment I'm simply creating a Label on the fly. So.. with a coroutine, I would need to create, then destroy the object every 1 second? Or can I easily manipulate the transparency.
Code (CSharp): Color setAlpha = new Color(1f, 0f, 0f, 0f); private void Update() { StartCoroutine(BloodSplatter()); } private IEnumerator BloodSplatter() { if (damaged) { setAlpha.a = 0.2f; damageImage.color = setAlpha; yield return new WaitForSeconds(0.1f); damaged = false; } else { setAlpha.a = 0f; damageImage.color = setAlpha; } } This should work perfectly fine.... If any more questions, post them here