Advertisement
lilos404

CameraFollow

Jul 18th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class CameraFollow : MonoBehaviour
  6. {
  7.     private Vector2 veclocity;
  8.  
  9.     public float smoothTimeY;
  10.     public float smoothTimeX;
  11.     public GameObject player;
  12.     public bool bounds;
  13.     public Vector3 minCamPos;
  14.     public Vector3 maxCamPos;
  15.     // Use this for initialization
  16.     void Start () {
  17.         player = GameObject.FindGameObjectWithTag("Player");
  18.     }
  19.    
  20.     // Update is called once per frame
  21.     void FixedUpdate ()
  22.     {
  23.         float posX = Mathf.SmoothDamp(transform.position.x, player.transform.position.x, ref veclocity.x, smoothTimeX);
  24.         float posY = Mathf.SmoothDamp(transform.position.y, player.transform.position.y, ref veclocity.y, smoothTimeY);
  25.  
  26.         transform.position = new Vector3(posX,posY,transform.position.z);
  27.  
  28.         if (bounds)
  29.         {
  30.             transform.position = new Vector3(Mathf.Clamp(transform.position.x , minCamPos.x , maxCamPos.x),
  31.                 Mathf.Clamp(transform.position.y, minCamPos.y, maxCamPos.y),
  32.                 Mathf.Clamp(transform.position.z, minCamPos.z, maxCamPos.z)
  33.            
  34.  
  35.                 );
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement