ofb/Assets/Scripts/CameraMovement.cs
slevy14 32a1412a57 added animation and camera
camera movement is very basic, animation is just right facing lol. also i know the organization is a bit of a mess, i promise i'll fix it
2023-04-19 21:34:00 -07:00

46 lines
1.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraMovement : MonoBehaviour {
GameObject player;
[Header("Movement Shifting")]
[SerializeField] float xOffset;
[SerializeField] float yOffset;
[SerializeField] float smoothing;
[Header("Locking")]
[SerializeField] bool xLocked;
[SerializeField] bool yLocked;
void Awake() {
FindPlayer();
}
// Update is called once per frame
void Update()
{
if (player != null) {
float xPos = transform.position.x;
float yPos = transform.position.y;
if (!xLocked) {
xPos = Mathf.Lerp(transform.position.x, player.transform.position.x + xOffset, Time.deltaTime * smoothing);
}
if (!yLocked) {
yPos = Mathf.Lerp(transform.position.y, player.transform.position.y + yOffset, Time.deltaTime * smoothing);
}
this.gameObject.transform.position = new Vector3 (xPos, yPos, transform.position.z);
}
}
public void FindPlayer() {
player = GameObject.FindGameObjectWithTag("Player");
}
}