Hi! it’s Šķoobi here and i have one quick question!
So i got a script from brackeys.com 2d assetpack where he made a invisible 2D boundaries it’s called GameSetup.js at the pong folder.And i converted it to C# and i wanted to do a getComponate stuff to make a 3d Box on the Invisible bourder so i don’t have just invisible walls how do i do it ?
ps : i can run the game and play it but it shows that it hasn’t place the box at its place…
Screenshot : Screenshot - 5f599d7bcb2b3005673c5375a4684281 - Gyazo
ps , ps : its a 2D game!!
Box Script
using UnityEngine;
using System.Collections;
public class CubeMoveTest : MonoBehaviour {
public GameObject TopWall;
private BoxCollider2D boxCollidder2;
void Awake ()
{
boxCollidder2 = TopWall.GetComponent<BoxCollider2D> ();
}
void start ()
{
transform.position = new Vector3 (boxCollidder2.transform.position.x, boxCollidder2.transform.position.y, 0);
}
}
boundaries Script
using UnityEngine;
using System.Collections;
public class ScreenWalls : MonoBehaviour {
//Reference the camera
public Camera mainCam;
//Reference the colliders we are going to adjust
public BoxCollider2D topWall;
public BoxCollider2D bottomWall;
public BoxCollider2D leftWall;
public BoxCollider2D rightWall;
void Start (){ //Only set this to Update if you know the screen size can change during a playsession.
//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);
bottomWall.size = new Vector2 (mainCam.ScreenToWorldPoint (new Vector3 (Screen.width * 2, 0f, 0f)).x, 1f);
bottomWall.center = new Vector2 (0f, mainCam.ScreenToWorldPoint (new Vector3( 0f, 0f, 0f)).y - 0.5f);
leftWall.size = new Vector2(1f, mainCam.ScreenToWorldPoint(new Vector3(0f, Screen.height*2f, 0f)).y);;
leftWall.center = new Vector2(mainCam.ScreenToWorldPoint(new Vector3(0f, 0f, 0f)).x - 0.5f, 0f);
rightWall.size = new Vector2(1f, mainCam.ScreenToWorldPoint(new Vector3(0f, Screen.height*2f, 0f)).y);
rightWall.center = new Vector2(mainCam.ScreenToWorldPoint(new Vector3(Screen.width, 0f, 0f)).x + 0.5f, 0f);
}
}