IMHOTEP Framework
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Pages
CreateBoxColliderForCanvas.cs
1 using UnityEngine;
2 using System.Collections;
3 
4 public class CreateBoxColliderForCanvas : MonoBehaviour {
5 
6  // Use this for initialization
7  void Start () {
8  RectTransform rt = this.GetComponent<RectTransform>();
9  if (rt != null)
10  {
11  BoxCollider bc = this.gameObject.AddComponent<BoxCollider>();
12  bc.center = Vector3.zero;
13  bc.size = new Vector3(rt.rect.width, rt.rect.height, 0.1f);
14  }
15  else
16  {
17  Debug.LogError("No rect trnasform found");
18  }
19 
20  }
21 }