ObstacleCollision.cs 763 B

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