Use coroutine to change wall transparency
This commit is contained in:
parent
107ef8ef12
commit
a8e1613e3f
2 changed files with 22 additions and 11 deletions
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using src.Base;
|
||||
using src.Helpers;
|
||||
|
@ -8,6 +9,7 @@ namespace src.Wall
|
|||
{
|
||||
public class WallTransparency : GameplayComponent
|
||||
{
|
||||
public float secondsToWait = 0.1f;
|
||||
private SpriteRenderer _spriteRenderer;
|
||||
private Color _originalSpriteColor;
|
||||
private bool _isTransparent;
|
||||
|
@ -16,9 +18,12 @@ namespace src.Wall
|
|||
{
|
||||
_spriteRenderer = GetComponentInChildren<SpriteRenderer>();
|
||||
_originalSpriteColor = _spriteRenderer.color;
|
||||
StartCoroutine(nameof(CheckIfSomethingNear));
|
||||
}
|
||||
|
||||
private void Update()
|
||||
private IEnumerator CheckIfSomethingNear()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
var position = transform.position;
|
||||
/* RayCast from the center of the tile up one distance and set layerMask to Player only! */
|
||||
|
@ -32,6 +37,9 @@ namespace src.Wall
|
|||
{
|
||||
BecomeOpaque();
|
||||
}
|
||||
|
||||
yield return new WaitForSeconds(secondsToWait);
|
||||
}
|
||||
}
|
||||
|
||||
private void ChangeSpriteAlpha(float alpha)
|
||||
|
|
|
@ -32,6 +32,9 @@ GraphicsSettings:
|
|||
- {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0}
|
||||
- {fileID: 10770, 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_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000,
|
||||
type: 0}
|
||||
|
|
Loading…
Reference in a new issue