Ejemplo 1: cámara sigue al jugador unidad 2d
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraController : MonoBehaviour
{
//Object you want to follow
public Transform target;
//Set to z -10
public Vector3 offset;
//How much delay on the follow
[Range(1, 10)]
public float smoothing;
private void FixedUpdate()
{
Follow();
}
void Follow()
{
Vector3 targetPosition = target.position + offset;
Vector3 smoothPosition = Vector3.Lerp(transform.position, targetPosition, smoothing * Time.fixedDeltaTime);
transform.position = smoothPosition;
}
}
Ejemplo 2: cómo hacer que la cámara siga al jugador unity 2d
public class CameraFollow : MonoBehaviour {
public GameObject Target;
private Vector3 Offset;
// Start is called before the first frame update
void Start() {
Offset = transform.position - Target.transform.position;
}
// Update is called once per frame
void Update() {
transform.position = Target.transform.position+Offset;
}
}
Ejemplo 3: seguimiento de cámara
public Transform player;
public Vector3 offset;
void LateUpdate()
{
transform.position = player.position + offset;
}
Ejemplo 4: la cámara sigue la unidad del jugador sin problemas
// CAMERA FOLLOW PLAYER - IN FIXEDUPDATE
Vector3.SmoothDamp(cam.position, transform.position + cameraOffset, ref cameraVelocity, CameraFollowSmoothTime);
cam.position = cam.position + cameraVelocity * Time.deltaTime;
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)