Implement transparent walls when player is near
This commit is contained in:
parent
9d544f7687
commit
1c55c754e1
9 changed files with 118 additions and 13 deletions
|
@ -71,7 +71,7 @@ SpriteRenderer:
|
||||||
m_LightmapParameters: {fileID: 0}
|
m_LightmapParameters: {fileID: 0}
|
||||||
m_SortingLayerID: 0
|
m_SortingLayerID: 0
|
||||||
m_SortingLayer: 0
|
m_SortingLayer: 0
|
||||||
m_SortingOrder: 1
|
m_SortingOrder: 0
|
||||||
m_Sprite: {fileID: 21300000, guid: 69237087e6b0b42ac8d25d0035b2e01b, type: 3}
|
m_Sprite: {fileID: 21300000, guid: 69237087e6b0b42ac8d25d0035b2e01b, type: 3}
|
||||||
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||||
m_FlipX: 0
|
m_FlipX: 0
|
||||||
|
@ -97,8 +97,6 @@ MonoBehaviour:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
movementSpeed: 4
|
movementSpeed: 4
|
||||||
respawnPosition: {fileID: 0}
|
respawnPosition: {fileID: 0}
|
||||||
bombPrefab: {fileID: 5909392949477884267, guid: 28467e0d65b5d3844bf1862ac0c49ad9,
|
|
||||||
type: 3}
|
|
||||||
--- !u!50 &6843575828445418653
|
--- !u!50 &6843575828445418653
|
||||||
Rigidbody2D:
|
Rigidbody2D:
|
||||||
serializedVersion: 4
|
serializedVersion: 4
|
||||||
|
|
|
@ -12,6 +12,7 @@ GameObject:
|
||||||
- component: {fileID: 4177940729222266823}
|
- component: {fileID: 4177940729222266823}
|
||||||
- component: {fileID: 4177940729222266822}
|
- component: {fileID: 4177940729222266822}
|
||||||
- component: {fileID: 2823577682722293689}
|
- component: {fileID: 2823577682722293689}
|
||||||
|
- component: {fileID: 4525879622828546227}
|
||||||
m_Layer: 8
|
m_Layer: 8
|
||||||
m_Name: bman_destructible_wall1
|
m_Name: bman_destructible_wall1
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
|
@ -97,6 +98,18 @@ MonoBehaviour:
|
||||||
type: 3}
|
type: 3}
|
||||||
exitDoorPrefab: {fileID: 1538214466168189615, guid: 519235375d069406f909265766078ad0,
|
exitDoorPrefab: {fileID: 1538214466168189615, guid: 519235375d069406f909265766078ad0,
|
||||||
type: 3}
|
type: 3}
|
||||||
|
--- !u!114 &4525879622828546227
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 4177940729222266681}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: f76d22fdcb894023bd111d6b5bc1da5e, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
--- !u!1 &5688352134163068791
|
--- !u!1 &5688352134163068791
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|
|
@ -91,6 +91,7 @@ GameObject:
|
||||||
- component: {fileID: 8360026854687715433}
|
- component: {fileID: 8360026854687715433}
|
||||||
- component: {fileID: 1860172021824364478}
|
- component: {fileID: 1860172021824364478}
|
||||||
- component: {fileID: 3937551180478767488}
|
- component: {fileID: 3937551180478767488}
|
||||||
|
- component: {fileID: 2850266447828806432}
|
||||||
m_Layer: 8
|
m_Layer: 8
|
||||||
m_Name: bman_destructible_wall2
|
m_Name: bman_destructible_wall2
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
|
@ -176,3 +177,15 @@ MonoBehaviour:
|
||||||
type: 3}
|
type: 3}
|
||||||
exitDoorPrefab: {fileID: 1538214466168189615, guid: 519235375d069406f909265766078ad0,
|
exitDoorPrefab: {fileID: 1538214466168189615, guid: 519235375d069406f909265766078ad0,
|
||||||
type: 3}
|
type: 3}
|
||||||
|
--- !u!114 &2850266447828806432
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 8729402555587492036}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: f76d22fdcb894023bd111d6b5bc1da5e, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
|
|
@ -11,6 +11,7 @@ GameObject:
|
||||||
- component: {fileID: 3400997238130971262}
|
- component: {fileID: 3400997238130971262}
|
||||||
- component: {fileID: 3305047832243218078}
|
- component: {fileID: 3305047832243218078}
|
||||||
- component: {fileID: 7808374684255412738}
|
- component: {fileID: 7808374684255412738}
|
||||||
|
- component: {fileID: 9150705305556807559}
|
||||||
m_Layer: 8
|
m_Layer: 8
|
||||||
m_Name: bman_indestructible_wall1
|
m_Name: bman_indestructible_wall1
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
|
@ -80,6 +81,18 @@ BoxCollider2D:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
m_Size: {x: 1, y: 1}
|
m_Size: {x: 1, y: 1}
|
||||||
m_EdgeRadius: 0
|
m_EdgeRadius: 0
|
||||||
|
--- !u!114 &9150705305556807559
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 5996206011854593075}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: f76d22fdcb894023bd111d6b5bc1da5e, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
--- !u!1 &6716060611887421146
|
--- !u!1 &6716060611887421146
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|
|
@ -8018,7 +8018,7 @@ Transform:
|
||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 266944714}
|
m_GameObject: {fileID: 266944714}
|
||||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
m_LocalPosition: {x: 0, y: 0, z: -2.7893844}
|
m_LocalPosition: {x: 0, y: 0, z: -10}
|
||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
m_Children:
|
m_Children:
|
||||||
- {fileID: 97386695}
|
- {fileID: 97386695}
|
||||||
|
@ -8156,7 +8156,7 @@ Transform:
|
||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 519420028}
|
m_GameObject: {fileID: 519420028}
|
||||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
m_LocalPosition: {x: 10.581639, y: -4.0430503, z: -2.7893844}
|
m_LocalPosition: {x: 10.590895, y: -4.0430503, z: -10}
|
||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
m_Children: []
|
m_Children: []
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
|
@ -8436,6 +8436,11 @@ PrefabInstance:
|
||||||
propertyPath: m_Name
|
propertyPath: m_Name
|
||||||
value: Player
|
value: Player
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 6843575828445418657, guid: d3055091a17dc4aa1accf2e33ccef144,
|
||||||
|
type: 3}
|
||||||
|
propertyPath: m_Layer
|
||||||
|
value: 15
|
||||||
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 6843575828445418654, guid: d3055091a17dc4aa1accf2e33ccef144,
|
- target: {fileID: 6843575828445418654, guid: d3055091a17dc4aa1accf2e33ccef144,
|
||||||
type: 3}
|
type: 3}
|
||||||
propertyPath: m_LocalPosition.x
|
propertyPath: m_LocalPosition.x
|
||||||
|
@ -8449,7 +8454,7 @@ PrefabInstance:
|
||||||
- target: {fileID: 6843575828445418654, guid: d3055091a17dc4aa1accf2e33ccef144,
|
- target: {fileID: 6843575828445418654, guid: d3055091a17dc4aa1accf2e33ccef144,
|
||||||
type: 3}
|
type: 3}
|
||||||
propertyPath: m_LocalPosition.z
|
propertyPath: m_LocalPosition.z
|
||||||
value: 7.2106156
|
value: 0
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 6843575828445418654, guid: d3055091a17dc4aa1accf2e33ccef144,
|
- target: {fileID: 6843575828445418654, guid: d3055091a17dc4aa1accf2e33ccef144,
|
||||||
type: 3}
|
type: 3}
|
||||||
|
@ -8496,10 +8501,5 @@ PrefabInstance:
|
||||||
propertyPath: respawnPosition
|
propertyPath: respawnPosition
|
||||||
value:
|
value:
|
||||||
objectReference: {fileID: 185746015}
|
objectReference: {fileID: 185746015}
|
||||||
- target: {fileID: 6843575828445418655, guid: d3055091a17dc4aa1accf2e33ccef144,
|
|
||||||
type: 3}
|
|
||||||
propertyPath: m_SortingOrder
|
|
||||||
value: 0
|
|
||||||
objectReference: {fileID: 0}
|
|
||||||
m_RemovedComponents: []
|
m_RemovedComponents: []
|
||||||
m_SourcePrefab: {fileID: 100100000, guid: d3055091a17dc4aa1accf2e33ccef144, type: 3}
|
m_SourcePrefab: {fileID: 100100000, guid: d3055091a17dc4aa1accf2e33ccef144, type: 3}
|
||||||
|
|
65
Assets/Scripts/src/Wall/WallTransparency.cs
Normal file
65
Assets/Scripts/src/Wall/WallTransparency.cs
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using src.Base;
|
||||||
|
using src.Helpers;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace src.Wall
|
||||||
|
{
|
||||||
|
public class WallTransparency : GameplayComponent
|
||||||
|
{
|
||||||
|
private SpriteRenderer _spriteRenderer;
|
||||||
|
private Color _originalSpriteColor;
|
||||||
|
private bool _isTransparent;
|
||||||
|
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
_spriteRenderer = GetComponentInChildren<SpriteRenderer>();
|
||||||
|
_originalSpriteColor = _spriteRenderer.color;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Update()
|
||||||
|
{
|
||||||
|
var position = transform.position;
|
||||||
|
/* RayCast from the center of the tile up one distance and set layerMask to Player only! */
|
||||||
|
var hit = Physics2D.Raycast(new Vector2(position.x + .5f, position.y + 0.5f),
|
||||||
|
Vector2.up, 1f, 1 << 15);
|
||||||
|
if (hit.collider)
|
||||||
|
{
|
||||||
|
BecomeTransparent();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
BecomeOpaque();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ChangeSpriteAlpha(float alpha)
|
||||||
|
{
|
||||||
|
_spriteRenderer.color =
|
||||||
|
new Color(_originalSpriteColor.r, _originalSpriteColor.g, _originalSpriteColor.b, alpha);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BecomeTransparent()
|
||||||
|
{
|
||||||
|
if (_isTransparent)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_isTransparent = true;
|
||||||
|
ChangeSpriteAlpha(0.5f);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BecomeOpaque()
|
||||||
|
{
|
||||||
|
if (!_isTransparent)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_isTransparent = false;
|
||||||
|
ChangeSpriteAlpha(1f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
3
Assets/Scripts/src/Wall/WallTransparency.cs.meta
Normal file
3
Assets/Scripts/src/Wall/WallTransparency.cs.meta
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f76d22fdcb894023bd111d6b5bc1da5e
|
||||||
|
timeCreated: 1560273099
|
|
@ -53,4 +53,4 @@ Physics2DSettings:
|
||||||
m_ColliderAsleepColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.36078432}
|
m_ColliderAsleepColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.36078432}
|
||||||
m_ColliderContactColor: {r: 1, g: 0, b: 1, a: 0.6862745}
|
m_ColliderContactColor: {r: 1, g: 0, b: 1, a: 0.6862745}
|
||||||
m_ColliderAABBColor: {r: 1, g: 1, b: 0, a: 0.2509804}
|
m_ColliderAABBColor: {r: 1, g: 1, b: 0, a: 0.2509804}
|
||||||
m_LayerCollisionMatrix: fffbfffffffbfffffffbfffffffffffffffbfffffffbfffffffffffffffffffffffbffffffffffffc8faffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
|
m_LayerCollisionMatrix: fffbffffff7bffffff7bffffffffffffff7bfffffffbfffffffffffffffffffffffbffffffffffffc87affffffffffffffffffffffffffffffffffffe9fbffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
|
||||||
|
|
|
@ -22,7 +22,7 @@ TagManager:
|
||||||
-
|
-
|
||||||
-
|
-
|
||||||
-
|
-
|
||||||
-
|
- Player
|
||||||
-
|
-
|
||||||
-
|
-
|
||||||
-
|
-
|
||||||
|
|
Loading…
Reference in a new issue