//void OnCollisionEnter2D(Collision2D other) //{ // RubyController player = other.gameObject.GetComponent<RubyController>(); // if (player != null) // { // player.ChangeHeath(-1); // } //} void OnTriggerEnter2D(Collider2D other) { RubyController controller = other.GetComponent <RubyController>(); if (controller != null) { controller.ChangeHeath(-1); } }
private void OnTriggerEnter2D(Collider2D collision) { RubyController rubyController = collision.GetComponent <RubyController>(); if (rubyController != null) { if (rubyController.heath < rubyController.maxHeath) { rubyController.ChangeHeath(1); Destroy(gameObject); rubyController.PlaySound(collectedClip); } } //Debug.Log("emter player" + collision); }