Showing posts with label orthographic. Show all posts
Showing posts with label orthographic. Show all posts

Friday, 13 October 2017

Unity 2D Camera Bounds

Watch Video Tutorial On Youtube


using UnityEngine;
using System.Collections;
 
public class CameraBounds : MonoBehaviour
{
 
    Vector3 screensize;
    public GameObject Right;
    public GameObject left;
    // Use this for initialization
 
 
    void Start()
    {
   screensize = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, 0));
 
    }
    // Update is called once per frame
    void Update()
    {
  screensize = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, 0));
  Right.transform.position = new Vector2(screensize.x + 0.65f, 0);
  left.transform.position = new Vector2((screensize.x - 0.65f) - 
   Camera.main.orthographicSize * Camera.main.aspect * 2f, 0);
    }
}