Forráskód Böngészése

Create scripts for obstacle collision

Till Steinert 3 éve
szülő
commit
1d04411c67

+ 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;
+    }
+}