Advertisement
gomuani

CamaraControler

Jun 1st, 2022
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.83 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class CameraControler : MonoBehaviour
  6. {
  7.     public Transform personaje;
  8.     private float tamanoCamara;
  9.     private float alturaPantalla;
  10.  
  11.     // Start is called before the first frame update
  12.     void Start()
  13.     {
  14.         tamanoCamara = Camera.main.orthographicSize;
  15.         alturaPantalla = tamanoCamara * 2;
  16.     }
  17.  
  18.     // Update is called once per frame
  19.     void Update()
  20.     {
  21.         CalcularPosicionCamara();
  22.     }
  23.  
  24.     void CalcularPosicionCamara()
  25.     {
  26.         int pantallaPersonaje = (int)(personaje.position.y/ alturaPantalla);
  27.         float alturaCamara = (pantallaPersonaje * alturaPantalla) + tamanoCamara;
  28.         transform.position = new Vector3(transform.position.x, alturaCamara, transform.position.z);
  29.      
  30.     }
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement