CoinCollection.cs 888 B

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