Advertisement
dantepw

Following Camera 2D Unity

Aug 14th, 2014
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Camera2d : MonoBehaviour {
  5.  
  6.     //quem ele vai seguir
  7.     public Transform player;
  8.  
  9.     public float smoothrate = 0.5f;
  10.  
  11.     public Transform thisTransform;
  12.     public Vector2 velocity;
  13.  
  14.  
  15.     // Use this for initialization
  16.     void Start () {
  17.         thisTransform = transform;
  18.         velocity = new Vector2 (0.5f, 0.5f);
  19.     }
  20.    
  21.  
  22.     void Update () {
  23.         Vector2 newPos2D = Vector2.zero;
  24.  
  25.         newPos2D.x = Mathf.SmoothDamp (thisTransform.position.x,   
  26.                                        player.position.x, ref velocity.x, smoothrate);
  27.  
  28.         newPos2D.y = Mathf.SmoothDamp (thisTransform.position.y,   
  29.                                        player.position.y, ref velocity.y, smoothrate);
  30.  
  31.         //atualiza a camera para a localizao do player
  32.         Vector3 newPos = new Vector3 (newPos2D.x, newPos2D.y, Transform.position.z);
  33.         transform.position = Vector3.Slerp (transform.position, newPos, Time.time);
  34.    
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement