Advertisement
CakeMeister

CameraFollow phan 6

Jun 27th, 2017
1,789
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.09 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Camerafollow : MonoBehaviour {
  6.     public float smoothtimeX, smoothtimeY;
  7.     public Vector2 velocity;
  8.  
  9.     public GameObject player;
  10.  
  11.     public Vector2 minpos, maxpos;
  12.     public bool bound;
  13.  
  14.     // Use this for initialization
  15.     void Start () {
  16.         player = GameObject.FindGameObjectWithTag("Player");
  17.     }
  18.    
  19.    
  20.     void FixedUpdate () {
  21.         float posX = Mathf.SmoothDamp(this.transform.position.x, player.transform.position.x, ref velocity.x, smoothtimeX);
  22.         float posY = Mathf.SmoothDamp(this.transform.position.y, player.transform.position.y, ref velocity.y, smoothtimeY);
  23.         transform.position = new Vector3(posX, posY, transform.position.z);
  24.  
  25.         if (bound)
  26.         {
  27.             transform.position = new Vector3(Mathf.Clamp(transform.position.x, minpos.x, maxpos.x),
  28.                 Mathf.Clamp(transform.position.y, minpos.y, maxpos.y),
  29.                 Mathf.Clamp(transform.position.z, transform.position.z, transform.position.z));
  30.              
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement