From 5c30563dcca70af1abc946e6f8fdbd437addea0f Mon Sep 17 00:00:00 2001 From: Jan Date: Sat, 21 Apr 2018 19:50:12 +0200 Subject: [PATCH] add collision for player --- Assets/Scripts/Entities/Entity.cs | 2 +- Assets/Scripts/Entities/Player.cs | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Assets/Scripts/Entities/Entity.cs b/Assets/Scripts/Entities/Entity.cs index 9c91404..1261eac 100644 --- a/Assets/Scripts/Entities/Entity.cs +++ b/Assets/Scripts/Entities/Entity.cs @@ -12,7 +12,7 @@ public abstract class Entity : MonoBehaviour{ } // kills the entity - public void Kill() + public virtual void Kill() { if(referringObjective != null) referringObjective.Remove (this.gameObject); diff --git a/Assets/Scripts/Entities/Player.cs b/Assets/Scripts/Entities/Player.cs index 4f16867..ceae2f0 100644 --- a/Assets/Scripts/Entities/Player.cs +++ b/Assets/Scripts/Entities/Player.cs @@ -6,7 +6,27 @@ public class Player : Mob { public Player() : base(null, 100 ) { - + } + private void OnCollisionEnter(Collision collision) + { + Debug.Log("Collision"); + if (collision.collider.tag == "wall") { + Kill(); + } + } + + private void OnTriggerEnter(Collider other) + { + if (other.tag == "door") { + Debug.Log("Open door"); + } + } + + public override void Kill() + { + base.Kill(); + Destroy(this.gameObject); + } }