Commit 4867336f authored by Martin Mihálik's avatar Martin Mihálik 🔥
Browse files

Walls

parent e3b47c74
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &2654140422281934948
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2654140422281934951}
- component: {fileID: 2654140422281934944}
- component: {fileID: 2654140422281934947}
- component: {fileID: 2654140422281934946}
- component: {fileID: 2654140422281934945}
- component: {fileID: 2654140422281934950}
m_Layer: 3
m_Name: Wall
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &2654140422281934951
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2654140422281934948}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!212 &2654140422281934944
SpriteRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2654140422281934948}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 0
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_Sprite: {fileID: 1579969085674745262, guid: fe414402022daf54092419715338b22d, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 1, y: 1}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0
--- !u!61 &2654140422281934947
BoxCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2654140422281934948}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 0
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0, y: 0}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0.5, y: 0.5}
oldSize: {x: 1, y: 1}
newSize: {x: 1, y: 1}
adaptiveTilingThreshold: 0.5
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 1, y: 1}
m_EdgeRadius: 0
--- !u!50 &2654140422281934946
Rigidbody2D:
serializedVersion: 4
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2654140422281934948}
m_BodyType: 1
m_Simulated: 1
m_UseFullKinematicContacts: 0
m_UseAutoMass: 0
m_Mass: 1
m_LinearDrag: 0
m_AngularDrag: 0.05
m_GravityScale: 1
m_Material: {fileID: 6200000, guid: 0af07f9debd10a04cbda18bd1aeb291a, type: 2}
m_Interpolate: 0
m_SleepingMode: 1
m_CollisionDetection: 0
m_Constraints: 0
--- !u!114 &2654140422281934945
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2654140422281934948}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 01e9ce25e2a99d149a174ad4098919ae, type: 3}
m_Name:
m_EditorClassIdentifier:
m_StartingHealth: 3
m_OnDamageTaken:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 2654140422281934950}
m_TargetAssemblyTypeName: WallController, Assembly-CSharp
m_MethodName: OnDamage
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
m_OnDeath:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 2654140422281934950}
m_TargetAssemblyTypeName: WallController, Assembly-CSharp
m_MethodName: OnDeath
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
--- !u!114 &2654140422281934950
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2654140422281934948}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 136730f820674ea4aaca1bc72ef473a2, type: 3}
m_Name:
m_EditorClassIdentifier:
m_NoDamageSprite: {fileID: 1579969085674745262, guid: fe414402022daf54092419715338b22d, type: 3}
m_SomeDamageSprite: {fileID: 3472043959254758212, guid: fe414402022daf54092419715338b22d, type: 3}
m_FullDamageSprite: {fileID: 8598481603908473379, guid: fe414402022daf54092419715338b22d, type: 3}
fileFormatVersion: 2
guid: 116e75d1ce3069d41b738de55fcdf8cd
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
......@@ -324,7 +324,10 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 01e9ce25e2a99d149a174ad4098919ae, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Health: 1
m_StartingHealth: 1
m_OnDamageTaken:
m_PersistentCalls:
m_Calls: []
m_OnDeath:
m_PersistentCalls:
m_Calls:
......@@ -467,6 +470,52 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1695424172
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1695424173}
- component: {fileID: 1695424174}
m_Layer: 3
m_Name: Walls
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1695424173
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1695424172}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1695424174
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1695424172}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: bea89f73c7d0f4f4eaa902784e4b227c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_WallPrefab: {fileID: 2654140422281934948, guid: 116e75d1ce3069d41b738de55fcdf8cd, type: 3}
m_WorldGrid: {fileID: 1364465087}
m_Player: {fileID: 512397504}
--- !u!1 &1877781301
GameObject:
m_ObjectHideFlags: 0
......
......@@ -4,19 +4,23 @@ using UnityEngine.Events;
public class DamageTaker : MonoBehaviour
{
[SerializeField] private uint m_Health;
[SerializeField] private uint m_StartingHealth;
public uint Health { get => m_Health; }
public uint StartingHealth { get => m_StartingHealth; }
public uint Health { get; private set; }
public bool Dead
{
get => Health == 0;
}
[SerializeField] private UnityEvent m_OnDamageTaken;
[SerializeField] private UnityEvent m_OnDeath;
private HashSet<long> m_DamageTaken;
private void Start()
{
Health = m_StartingHealth;
m_DamageTaken = new HashSet<long>();
}
......@@ -39,14 +43,15 @@ public class DamageTaker : MonoBehaviour
return;
}
if (m_Health <= dealer.Damage)
if (Health <= dealer.Damage)
{
m_Health = 0;
Health = 0;
m_OnDeath.Invoke();
}
else
{
m_Health -= dealer.Damage;
Health -= dealer.Damage;
m_OnDamageTaken.Invoke();
m_DamageTaken.Add(dealer.Id);
}
}
......
fileFormatVersion: 2
guid: 062053911a0b0e6469d30c4d627e902c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
public class WallController : MonoBehaviour
{
[SerializeField] private Sprite m_NoDamageSprite;
[SerializeField] private Sprite m_SomeDamageSprite;
[SerializeField] private Sprite m_FullDamageSprite;
private SpriteRenderer m_SpriteRenderer;
private DamageTaker m_DamageTaker;
private void Start()
{
m_SpriteRenderer = GetComponent<SpriteRenderer>();
m_DamageTaker = GetComponent<DamageTaker>();
}
public void OnDamage()
{
SetTexture(m_DamageTaker.Health / (float)m_DamageTaker.StartingHealth);
}
public void OnDeath()
{
Destroy(gameObject);
}
private void SetTexture(float healthRatio)
{
if (healthRatio > 2 / 3f)
{
m_SpriteRenderer.sprite = m_NoDamageSprite;
}
else if (healthRatio > 1 / 3f)
{
m_SpriteRenderer.sprite = m_SomeDamageSprite;
}
else
{
m_SpriteRenderer.sprite = m_FullDamageSprite;
}
}
}
fileFormatVersion: 2
guid: 136730f820674ea4aaca1bc72ef473a2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
public class WallSpawner : MonoBehaviour
{
[SerializeField] private GameObject m_WallPrefab;
[SerializeField] private Grid m_WorldGrid;
[SerializeField] private Transform m_Player;
private void Update()
{
if (Input.GetKeyDown(KeyCode.W))
{
SpawnWall(m_Player.position, gameObject.transform);
}
}
private void SpawnWall(Vector2 position, Transform parent)
{
var cell = m_WorldGrid.LocalToCell(position);
cell.y += 2;
position = m_WorldGrid.GetCellCenterWorld(cell);
Instantiate(m_WallPrefab, position, Quaternion.identity, parent);
}
}
fileFormatVersion: 2
guid: bea89f73c7d0f4f4eaa902784e4b227c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment