Make player die when in contact wiht enemy

This commit is contained in:
Denis-Cosmin Nutiu 2019-09-07 12:17:37 +03:00
parent 5e6c27b672
commit a9023a7efd
3 changed files with 51 additions and 6 deletions

View file

@ -185,17 +185,21 @@ namespace src.Player
other.isTrigger = false;
}
}
public void OnCollisionEnter2D(Collision2D other)
{
if (other.collider.CompareTag("Enemy"))
{
OnContactWithEnemy();
}
}
public void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Explosion"))
{
OnExplosion();
}
if (other.CompareTag("Enemy"))
{
OnContactWithEnemy();
}
}
public void OnExplosion()

View file

@ -53,4 +53,4 @@ Physics2DSettings:
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_ColliderAABBColor: {r: 1, g: 1, b: 0, a: 0.2509804}
m_LayerCollisionMatrix: fffbffffff3bffffff3bffffffffffffff3bfffffffbfffffffffffffffffffffffbffffffffffffc80affffffffffffff7bfffffffbffffe93bffffe9abffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
m_LayerCollisionMatrix: fffbffffff3bffffff3bffffffffffffff3bfffffffbfffffffffffffffffffffffbffffffffffffc80affffffffffffff7bfffffffbffffe9bbffffe9ebffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff

41
enemy.patch Normal file
View file

@ -0,0 +1,41 @@
diff --git a/Assets/Scripts/src/Player/PlayerController.cs b/Assets/Scripts/src/Player/PlayerController.cs
index 943f824..86df39d 100644
--- a/Assets/Scripts/src/Player/PlayerController.cs
+++ b/Assets/Scripts/src/Player/PlayerController.cs
@@ -185,17 +185,21 @@ namespace src.Player
other.isTrigger = false;
}
}
-
+
+ public void OnCollisionEnter2D(Collision2D other)
+ {
+ if (other.collider.CompareTag("Enemy"))
+ {
+ OnContactWithEnemy();
+ }
+ }
+
public void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Explosion"))
{
OnExplosion();
}
- if (other.CompareTag("Enemy"))
- {
- OnContactWithEnemy();
- }
}
public void OnExplosion()
diff --git a/ProjectSettings/Physics2DSettings.asset b/ProjectSettings/Physics2DSettings.asset
index 8c8f397..07be3db 100644
--- a/ProjectSettings/Physics2DSettings.asset
+++ b/ProjectSettings/Physics2DSettings.asset
@@ -53,4 +53,4 @@ Physics2DSettings:
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_ColliderAABBColor: {r: 1, g: 1, b: 0, a: 0.2509804}
- m_LayerCollisionMatrix: fffbffffff3bffffff3bffffffffffffff3bfffffffbfffffffffffffffffffffffbffffffffffffc80affffffffffffff7bfffffffbffffe93bffffe9abffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
+ m_LayerCollisionMatrix: fffbffffff3bffffff3bffffffffffffff3bfffffffbfffffffffffffffffffffffbffffffffffffc80affffffffffffff7bfffffffbffffe9bbffffe9ebffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff