Guest User

Untitled

a guest
Oct 22nd, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. sealed class TestDoubleQuesionMark : MonoBehaviour {
  4. void OnEnable () {
  5. Test<BoxCollider> ();
  6. Test<SphereCollider> ();
  7. Test<CharacterController> ();
  8. Test<Rigidbody> ();
  9. }
  10.  
  11. void Test<T> () where T : Component {
  12. Debug.Log (string.Format ("TEST: {0}", typeof (T).Name));
  13. var component = GetComponent<T> () ?? gameObject.AddComponent<T> ();
  14. }
  15.  
  16. void Test1<T> () where T : Component {
  17. Debug.Log (string.Format ("TEST: {0}", typeof (T).Name));
  18. var component = GetComponent<T> ();
  19. if (component == null) {
  20. component = gameObject.AddComponent<T> ();
  21. }
  22. }
  23. }
Add Comment
Please, Sign In to add comment