Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private float transparency = 1f;
- private bool transparencyGoingUp = false;
- private bool currentlyFlashing = true;
- (when the player moves, i set currently flashing to false, meaning the flashing cycle will finish and go back to 1 (filly visible) but not keep flashing)
- also excuse the weird condition checks for transparency == 1/0.1. I had issues with it making the float be (ex) 0.09 instead of 0.1, so this way made it work
- The following coroutine is called every frame (in Update())
- IEnumerator flashTransparency(float waitTime)
- {
- //update the alpha (transparency)
- Color tempColor = cubee.renderer.material.color;
- tempColor.a = transparency;
- cubee.renderer.material.color = tempColor;
- //adjust what the alpha will be updated to next time this coroutine is run
- if(transparencyGoingUp)
- {
- transparency += 0.1f;
- if(transparency > 0.95f && transparency < 1.2f && currentlyFlashing) //if(transparency == 1)
- transparencyGoingUp = false;
- }
- else //if transparency is going down
- {
- transparency -= 0.1f;
- if(transparency < 0.2f && transparency > 0.08f) //if(transparency == 0.1f)
- transparencyGoingUp = true;
- }
- //wait before calling this again so it isnt called every frame and therefore flash way too fast
- yield return new WaitForSeconds(waitTime / 9); // 9 because it updates 9 times per direction, so waitTime == total time to go top to bot or bot to top
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement