void OnTriggerStay2D(Collider2D other) { SarahController controller = other.GetComponent<SarahController >(); if (controller != null) { controller.ChangeHealth(-1); // Damage on stepping on spikes } }
void OnCollisionEnter2D(Collision2D other) // Check for collision { SarahController player = other.gameObject.GetComponent <SarahController>(); if (player != null) { player.ChangeHealth(-1); //Change Player Health } }
void OnTriggerEnter2D(Collider2D other) { SarahController controller = other.GetComponent <SarahController>(); if (controller != null) { if (controller.health < controller.maxHealth) { controller.ChangeHealth(1); // Add Health on eating berry Destroy(gameObject); } } }