void OnTriggerEnter(Collider other) { if (other.transform.gameObject.GetComponent <Pirate>() != null) { TotalCoins = PlayerPrefs.GetInt("TotalCoins", 0); CurrentAmountCoins = TotalCoins + 1; player = FindObjectOfType <Pirate>(); player.PlayCoinSound(); PlayerPrefs.SetInt("TotalCoins", CurrentAmountCoins); manager = FindObjectOfType <GameManager>(); manager.IncreaseCurrentCoins(); Destroy(this.gameObject); } }