CoinCollection.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. spawn = GameObject.FindGameObjectWithTag("Route").GetComponent<CoinCreation>();
  14. }
  15. // Update is called once per frame
  16. void Update()
  17. {
  18. }
  19. //Keep count of collisions with player
  20. private void OnTriggerEnter(Collider other)
  21. {
  22. Debug.Log("Coin Hit!");
  23. if (other.gameObject.CompareTag("bike"))
  24. {
  25. Debug.Log("Collecting Coin");
  26. // Increase Hit Counter
  27. var bike = other.gameObject;
  28. bike.GetComponent<PlayerStats>().IncreaseCoinCounter();
  29. coinPool.ReturnToPool(gameObject);
  30. //sobald ein coin eingesammelt einen neuen erstellen/platzieren
  31. spawn.UpdateCoins();
  32. }
  33. }
  34. }