Created
June 18, 2017 05:55
-
-
Save unity3dcollege/95153d4d9ad6e01a0ef9aae92d5a82c4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
[RequireComponent(typeof(RectTransform))] | |
public class VRUIItem : MonoBehaviour | |
{ | |
private BoxCollider boxCollider; | |
private RectTransform rectTransform; | |
private void OnEnable() | |
{ | |
ValidateCollider(); | |
} | |
private void OnValidate() | |
{ | |
ValidateCollider(); | |
} | |
private void ValidateCollider() | |
{ | |
rectTransform = GetComponent<RectTransform>(); | |
boxCollider = GetComponent<BoxCollider>(); | |
if (boxCollider == null) | |
{ | |
boxCollider = gameObject.AddComponent<BoxCollider>(); | |
} | |
boxCollider.size = rectTransform.sizeDelta; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment