Hello all,
i have been trying to resize a boxcollider2d with code and it works with js but not with c# what am i doing wrong?
i have the codes:
C#
using UnityEngine;
using System.Collections;
public class gameSetup : MonoBehaviour {
public Camera mainCam;
public BoxCollider2D topWall;
// Update is called once per frame
void update () {
topWall.size = new Vector2 (mainCam.ScreenToWorldPoint (new Vector3 (Screen.width * 2f, 0f, 0f)).x, 1f);
topWall.center = new Vector2 (0f, mainCam.ScreenToWorldPoint (new Vector3 (0f, Screen.height, 0f)).y + 0.5f);
}
}
JS
#pragma strict
//Reference the camera
var mainCam : Camera;
//Reference the colliders we are going to adjust
var topWall : BoxCollider2D;
function Update () {
//Move each wall to its edge location:
topWall.size = new Vector2 (mainCam.ScreenToWorldPoint (new Vector3 (Screen.width * 2f, 0f, 0f)).x, 1f);
topWall.center = new Vector2 (0f, mainCam.ScreenToWorldPoint (new Vector3 ( 0f, Screen.height, 0f)).y + 0.5f);
}
And i have dragged camera and wall to the correct variables
Kind regards
Isak