Hi Guys, I’m a beginner. I want to adjust a Box Collider 2D to the screen size, so my player object can’t get out of screen. I used the following code, but the size doesn’t change if I hit the play button, also the checkbox to enable or disable the script isn’t available. Answers to similar questions seem not work.
using UnityEngine;
using System.Collections;
public class Frame : MonoBehaviour
{
// Use this for initialization
BoxCollider2D bc;
float height;
float width;
void start() {
height = Screen.height;
width = Screen.width;
bc = this.GetComponent<BoxCollider2D>();
bc.size = new Vector2 ( width, height);
}
}