Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Camera2d : MonoBehaviour {
- //quem ele vai seguir
- public Transform player;
- public float smoothrate = 0.5f;
- public Transform thisTransform;
- public Vector2 velocity;
- // Use this for initialization
- void Start () {
- thisTransform = transform;
- velocity = new Vector2 (0.5f, 0.5f);
- }
- void Update () {
- Vector2 newPos2D = Vector2.zero;
- newPos2D.x = Mathf.SmoothDamp (thisTransform.position.x,
- player.position.x, ref velocity.x, smoothrate);
- newPos2D.y = Mathf.SmoothDamp (thisTransform.position.y,
- player.position.y, ref velocity.y, smoothrate);
- //atualiza a camera para a localizao do player
- Vector3 newPos = new Vector3 (newPos2D.x, newPos2D.y, Transform.position.z);
- transform.position = Vector3.Slerp (transform.position, newPos, Time.time);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement