16 using System.Collections;
17 using System.Collections.Generic;
25 #if UNITY_2018 || UNITY_2019_1
27 public static bool TryGetComponent<T>(
this GameObject obj, out T target) where T : Component
29 target = obj.GetComponent<T>();
30 return target !=
null;
33 public static bool TryGetComponent<T>(
this MonoBehaviour monoBehaviour, out T target) where T : Component
35 return monoBehaviour.gameObject.TryGetComponent<T>(out target);
38 public static bool TryGetComponent<T>(
this Transform transform, out T target) where T : Component
40 return transform.gameObject.TryGetComponent<T>(out target);