Check out example codes for "unity prevent object from leaving camera view". It will help you in understanding the concepts better.

Code Example 1

using UnityEngine; 
using System.Collections; 
public class Example : MonoBehaviour {
  void Update() {         
    Vector3 pos = Camera.main.WorldToViewportPoint (transform.position);         
    pos.x = Mathf.Clamp01(pos.x);         
    pos.y = Mathf.Clamp01(pos.y);         
    transform.position = Camera.main.ViewportToWorldPoint(pos);     
  } 
}

Learn ReactJs, React Native from akashmittal.com