You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
PhishingAwarenessSimulation/Assets/Scripts/CameraController.cs

52 lines
1.7 KiB
C#

using UnityEngine;
public class CameraController : MonoBehaviour
{
[Header("Follow Target")]
public Transform followTarget; // The player (root GameObject)
[Header("Zoom Settings")]
public Transform zoomTarget; // Target to zoom into (e.g. computer screen)
public float followSmoothness = 5f;
public float zoomSpeed = 2f;
private Vector3 initialOffset;
private bool isZooming = false;
void Start()
{
if (followTarget == null)
{
Debug.LogError("❌ followTarget not assigned!");
return;
}
// Calculate offset from current camera position
initialOffset = transform.position - followTarget.position;
}
void LateUpdate()
{
if (isZooming && zoomTarget != null)
{
// Smooth zoom toward target (e.g., computer screen)
transform.position = Vector3.Lerp(transform.position, zoomTarget.position, zoomSpeed * Time.deltaTime);
transform.rotation = Quaternion.Slerp(transform.rotation,
Quaternion.LookRotation(zoomTarget.position - transform.position),
zoomSpeed * Time.deltaTime);
}
else if (followTarget != null)
{
// Follow player with initial offset
Vector3 targetPosition = followTarget.position + initialOffset;
transform.position = Vector3.Lerp(transform.position, targetPosition, followSmoothness * Time.deltaTime);
transform.LookAt(followTarget);
}
}
public void StartZoom()
{
isZooming = true;
}
}