private void OnTriggerEnter2D(Collider2D other) { MainCharacter character = other.GetComponentInParent <MainCharacter>(); if (character != null) { CharacterCoinController coinController = character.GetComponentInChildren <CustomCharacterController>().coinController; audioSource.PlayOneShot(InteractionSound, Random.Range(minSound, maxSound)); coinController.AddCoins(price); gameObject.GetComponent <Renderer>().enabled = false; DisableColider(); DestroyAfterSoundFinished(); } }
protected override void OnCollisionEnter2D(Collision2D collision) { MainCharacter character = collision.gameObject.GetComponent <MainCharacter>(); if (character != null) { CharacterCoinController coinController = character.GetComponentInChildren <CustomCharacterController>().coinController; DisableColider(); audioSource.PlayOneShot(InteractionSound, 1f); coinController.AddCoins(price); gameObject.GetComponent <Renderer>().enabled = false; DestroyAfterSoundFinished(); } }