Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- sealed class TestDoubleQuesionMark : MonoBehaviour {
- void OnEnable () {
- Test<BoxCollider> ();
- Test<SphereCollider> ();
- Test<CharacterController> ();
- Test<Rigidbody> ();
- }
- void Test<T> () where T : Component {
- Debug.Log (string.Format ("TEST: {0}", typeof (T).Name));
- var component = GetComponent<T> () ?? gameObject.AddComponent<T> ();
- }
- void Test1<T> () where T : Component {
- Debug.Log (string.Format ("TEST: {0}", typeof (T).Name));
- var component = GetComponent<T> ();
- if (component == null) {
- component = gameObject.AddComponent<T> ();
- }
- }
- }
Add Comment
Please, Sign In to add comment