using UnityEngine; using UnityEngine.Events; public class ContactAction : MonoBehaviour { public bool isCollisionActive; // Ob man wirklich mit dem Ding physisch kollidiert (oder ob man durch kann) public UnityEvent onContact; private Collider2D colliderComponent; private GameObject thingThatCollided; // wird wohl meist der Spieler sein private TextNote textNote; private void Awake() { colliderComponent = this.GetComponent(); } // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { colliderComponent.isTrigger = !isCollisionActive; } public void Kill() { if (thingThatCollided.GetComponent() != null) { thingThatCollided.GetComponent().Kill(); } } public void Yeet() { if (thingThatCollided.GetComponent() != null) { thingThatCollided.GetComponent().AddForce(Vector2.up * 10f, ForceMode2D.Impulse); } } public void ShowText() { if (this.gameObject.GetComponent() != null) { textNote = this.gameObject.GetComponent(); GameManager.gameManager.ShowText(textNote.headline, textNote.content); } else { Debug.Log("keine Component TextNote vorhanden"); } } private void OnCollisionEnter2D(Collision2D collision) { if (isCollisionActive) { thingThatCollided = collision.gameObject; onContact.Invoke(); } } private void OnTriggerEnter2D(Collider2D collider) { if (!isCollisionActive) { thingThatCollided = collider.gameObject; onContact.Invoke(); } } }