// When this game object intersects a collider with 'is trigger' checked, // store a reference to that collider in a variable named 'other'.. void OnTriggerEnter(Collider other) { // ..and if the game object we intersect has the tag 'Pick Up' assigned to it.. if (other.gameObject.CompareTag("Pick Up")) { // Make the other game object (the pick up) inactive, to make it disappear other.gameObject.SetActive(false); // Add one to the score variable 'count' PickupStats.IncrementCount(); } }
void OnTriggerEnter2D(Collider2D other) { if (other.CompareTag("EnemyWeapon") && !invulnerable && !beenHurt && !dashing) { PlayerHurt(other.gameObject); } if (other.CompareTag("HealthPickup")) { PickupStats pickup = other.GetComponent <PickupStats>(); currentHealth += pickup.healthUp; maxHealth += pickup.maxHealthUp; healthBar.transform.localScale = new Vector3(originalHealthLength * (currentHealth / maxHealth), healthBar.transform.localScale.y, healthBar.transform.localScale.z); if (currentHealth > maxHealth) { currentHealth = maxHealth; } } // check if collectable }