Use coroutine to change wall transparency

This commit is contained in:
Denis-Cosmin Nutiu 2019-06-22 10:01:55 +03:00
parent 107ef8ef12
commit a8e1613e3f
2 changed files with 22 additions and 11 deletions

View file

@ -1,4 +1,5 @@
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using src.Base; using src.Base;
using src.Helpers; using src.Helpers;
@ -8,6 +9,7 @@ namespace src.Wall
{ {
public class WallTransparency : GameplayComponent public class WallTransparency : GameplayComponent
{ {
public float secondsToWait = 0.1f;
private SpriteRenderer _spriteRenderer; private SpriteRenderer _spriteRenderer;
private Color _originalSpriteColor; private Color _originalSpriteColor;
private bool _isTransparent; private bool _isTransparent;
@ -16,9 +18,12 @@ namespace src.Wall
{ {
_spriteRenderer = GetComponentInChildren<SpriteRenderer>(); _spriteRenderer = GetComponentInChildren<SpriteRenderer>();
_originalSpriteColor = _spriteRenderer.color; _originalSpriteColor = _spriteRenderer.color;
StartCoroutine(nameof(CheckIfSomethingNear));
} }
private void Update() private IEnumerator CheckIfSomethingNear()
{
while (true)
{ {
var position = transform.position; var position = transform.position;
/* RayCast from the center of the tile up one distance and set layerMask to Player only! */ /* RayCast from the center of the tile up one distance and set layerMask to Player only! */
@ -32,6 +37,9 @@ namespace src.Wall
{ {
BecomeOpaque(); BecomeOpaque();
} }
yield return new WaitForSeconds(secondsToWait);
}
} }
private void ChangeSpriteAlpha(float alpha) private void ChangeSpriteAlpha(float alpha)

View file

@ -32,6 +32,9 @@ GraphicsSettings:
- {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0} - {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0} - {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 10783, guid: 0000000000000000f000000000000000, type: 0} - {fileID: 10783, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 16000, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 17000, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 16001, guid: 0000000000000000f000000000000000, type: 0}
m_PreloadedShaders: [] m_PreloadedShaders: []
m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000, m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000,
type: 0} type: 0}