Fortiter
0
Q:

unity prevent object from leaving camera view

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);     
  } 
}
0

New to Communities?

Join the community