ofb/Assets/Scripts/CameraMovement.cs
slevy14 405e20ca2f lots of small changes lol
worked on tambourine level layout, improved tambourine throwing, created enemy respawn system
2023-04-29 14:51:50 -07:00

49 lines
1.2 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraMovement : MonoBehaviour {
public 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");
// if (player == null) {
// print("null player!");
// }
}
}