Browse Source

Tag looks in parent

main
Joshua Reason 1 year ago
parent
commit
8122c6694a
3 changed files with 41 additions and 1 deletions
  1. +1
    -1
      Assets/Scripts/BoatController.cs
  2. +29
    -0
      Assets/Scripts/Utility/GameObjectExtension.cs
  3. +11
    -0
      Assets/Scripts/Utility/GameObjectExtension.cs.meta

+ 1
- 1
Assets/Scripts/BoatController.cs View File

@ -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}");

+ 29
- 0
Assets/Scripts/Utility/GameObjectExtension.cs View File

@ -0,0 +1,29 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using NaughtyAttributes;
/// <summary>
///
/// </summary>
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;
}
}

+ 11
- 0
Assets/Scripts/Utility/GameObjectExtension.cs.meta View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 372b54ac7f1e6564993301c9b3a0cb22
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Loading…
Cancel
Save