CoinCollection.cs 858 B

12345678910111213141516171819202122232425262728293031323334
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class CoinCollection : MonoBehaviour
  5. {
  6. public GameObject coinPool;
  7. // Start is called before the first frame update
  8. void Start()
  9. {
  10. coinPool = GameObject.FindGameObjectWithTag("CoinPool").GetComponent<CoinPool>();
  11. }
  12. // Update is called once per frame
  13. void Update()
  14. {
  15. }
  16. //Keep count of collisions with player
  17. private void OnTriggerEnter(Collider other)
  18. {
  19. Debug.Log("Coin Hit!");
  20. if (other.gameObject.CompareTag("bike"))
  21. {
  22. Debug.Log("Collecting Coin");
  23. // Increase Hit Counter
  24. var bike = other.gameObject;
  25. bike.GetComponent<PlayerStats>().IncreaseCoinCounter();
  26. coinPool.ReturnToPool(gameObject);
  27. }
  28. }
  29. }