// Beispiel: Überschreibung von CanPickup() -> können es nur einsammeln, wenn wir nach rechts schauen protected override bool CanPickup() { Player_Damageable pDama = FindObjectOfType <Player_Damageable>(); int health = pDama.Health; int maxHealth = pDama.MaxHealth; return(health < maxHealth); }
protected override void Pickup() { //Debug.Log("You picked something up."); Instantiate(particles, transform.position, particles.transform.rotation); // Quaternion.identity = keine Rotation Player_Damageable pDama = FindObjectOfType <Player_Damageable>(); pDama.HealCompletely(); }
private Player_Damageable player; // Cache public void OnTriggerEnter2D(Collider2D collision) { if (collision.CompareTag("Player")) { if (!player) // Falls wir den Spieler noch nicht kennen, suchen wir ihn; { player = collision.GetComponent <Player_Damageable>(); } player.Kill(); } }
private Player_Damageable player; // Cache // Stay funktioniert nur, weil wir Invincibility/Damage-Cooldown haben. // Ansonsten wäre OnTriggerEnter2D besser. private void OnTriggerStay2D(Collider2D collision) { if (!collision.CompareTag("Player")) { return; } if (!player) { player = collision.GetComponent <Player_Damageable>(); // Alternative: LevelManager } player.TakeDamage(damage); }