瀏覽代碼

Create scripts for obstacle collision

Till Steinert 3 年之前
父節點
當前提交
1d04411c67
共有 2 個文件被更改,包括 56 次插入0 次删除
  1. 32 0
      Assets/Scripts/Obstacles/ObstacleCollision.cs
  2. 24 0
      Assets/Scripts/Obstacles/PlayerStats.cs

+ 32 - 0
Assets/Scripts/Obstacles/ObstacleCollision.cs

@@ -0,0 +1,32 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class ObstacleCollision : MonoBehaviour
+{
+    // Start is called before the first frame update
+    void Start()
+    {
+        
+    }
+
+    // Update is called once per frame
+    void Update()
+    {
+        
+    }
+
+    //Keep count of collisions with player
+    private void OnTriggerEnter(Collider other)
+    {
+        Debug.Log("Detected Obstacle Collision!");
+        if (other.gameObject.CompareTag("bike"))
+        {
+            Debug.Log("Detected Bike Collision!");
+            // Increase Hit Counter
+            var bike = other.gameObject;
+            Debug.Log(bike.name);
+            bike.GetComponent<PlayerStats>().IncreaseCollisionCounter();
+        }
+    }
+}

+ 24 - 0
Assets/Scripts/Obstacles/PlayerStats.cs

@@ -0,0 +1,24 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class PlayerStats : MonoBehaviour
+{
+    public int collisionCounter;
+    // Start is called before the first frame update
+    void Start()
+    {
+        collisionCounter = 0;
+    }
+
+    // Update is called once per frame
+    void Update()
+    {
+        
+    }
+
+    public void IncreaseCollisionCounter() 
+    {
+        collisionCounter += 1;
+    }
+}