Guest User

Untitled

a guest
Jan 24th, 2017
465
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.05 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class CameraController : MonoBehaviour {
  5.  
  6.     public Transform Character;
  7.     private float XThreshold = 3.0f;
  8.     private float YThreshold = 3.0f;
  9.  
  10.     // Use this for initialization
  11.     void Start () {
  12.    
  13.     }
  14.    
  15.     // Update is called once per frame
  16.     void Update () {
  17.         if (Character.position.x > transform.position.x + XThreshold) {
  18.             transform.position = new Vector3(Character.position.x-XThreshold, transform.position.y, transform.position.x);
  19.         } else if (Character.position.x < transform.position.x - XThreshold) {
  20.             transform.position = new Vector3(Character.position.x+XThreshold, transform.position.y, transform.position.x);
  21.         }
  22.  
  23.         if (Character.position.y > transform.position.y + YThreshold) {
  24.             transform.position = new Vector3(transform.position.x, Character.position.y-YThreshold, transform.position.x);
  25.         } else if (Character.position.y < transform.position.y - XThreshold) {
  26.             transform.position = new Vector3(transform.position.x, Character.position.y+YThreshold, transform.position.x);
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment