2
0

CoinCollection.cs 866 B

123456789101112131415161718192021222324252627282930313233
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System.Linq;
  5. using JetBrains.Annotations;
  6. using Pools;
  7. //Jeder Coin besitzt dieses Skript
  8. public class CoinCollection : MonoBehaviour
  9. {
  10. private CoinPool coinPool;
  11. // Start is called before the first frame update
  12. void Start()
  13. {
  14. coinPool = GameObject.FindGameObjectWithTag("CoinPool").GetComponent<CoinPool>();
  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. // Increase Hit Counter
  23. var bike = other.gameObject;
  24. bike.GetComponent<PlayerStats>().IncreaseCoinCounter();
  25. //Returning Coin to Pool
  26. coinPool.ReturnToPool(gameObject);
  27. }
  28. }
  29. }