diff --git a/Assets/Scripts/BoatController.cs b/Assets/Scripts/BoatController.cs index 4f5994e..e76683f 100644 --- a/Assets/Scripts/BoatController.cs +++ b/Assets/Scripts/BoatController.cs @@ -101,7 +101,7 @@ public class BoatController : MonoBehaviour public void OnCollisionEnter(Collision collision) { - if (collision.gameObject.CompareTag("Obstacle")) + if (collision.gameObject.isTagInParent("Obstacle")) { Debug.Log($"Hitting: {collision.gameObject} Foce: {collision.impulse * ObstacleBounce}"); diff --git a/Assets/Scripts/Utility/GameObjectExtension.cs b/Assets/Scripts/Utility/GameObjectExtension.cs new file mode 100644 index 0000000..41a58fd --- /dev/null +++ b/Assets/Scripts/Utility/GameObjectExtension.cs @@ -0,0 +1,29 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using NaughtyAttributes; + + +/// +/// +/// +public static class GameObjectExtension +{ + + public static bool isTagInParent(this GameObject go, string tag) + { + Transform current = go.transform; + while (current != null) + { + if (current.gameObject.CompareTag(tag)) + return true; + + current = current.parent; + } + + return false; + } + + + +} \ No newline at end of file diff --git a/Assets/Scripts/Utility/GameObjectExtension.cs.meta b/Assets/Scripts/Utility/GameObjectExtension.cs.meta new file mode 100644 index 0000000..06734c5 --- /dev/null +++ b/Assets/Scripts/Utility/GameObjectExtension.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 372b54ac7f1e6564993301c9b3a0cb22 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: