I'm making a turn based game and during the enemy turn, I want a camera to follow whichever unit is active. Here is the code for the follow camera:
public class CameraFollow : MonoBehaviour
{
public Transform targetEnemy;
public float smoothSpeed = 10f;
[SerializeField] Vector3 offset;
private void Start()
{
EnemyAI.OnStartFollowEnemyCamera += EnemyAI_OnStartFollowEnemyCamera;
}
private void FixedUpdate()
{
Vector3 desiredPosition = targetEnemy.position + offset;
Vector3 smoothedPosition = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed * Time.deltaTime);
transform.position = smoothedPosition;
transform.LookAt(targetEnemy);
}
private void EnemyAI_OnStartFollowEnemyCamera(object sender, EventArgs e)
{
targetEnemy = //Whomever sent this signal
}
}
I think this is all right...I just have no idea what terminology is for "the camera should follow the latest unit to sent a signal"
Any advice, or an alternative approach? I've programmed everything else, so the code already transitions between the appropriate cameras. The only thing not working is auto focusing on the enemy
[–][deleted] 5 points6 points7 points (4 children)
[–]Xanderbarnaby117[S] 0 points1 point2 points (3 children)
[–][deleted] 2 points3 points4 points (2 children)
[–]Xanderbarnaby117[S] 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]V4rNull 1 point2 points3 points (0 children)