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
This commit is contained in:
45
Assets/Scripts/CameraMovement.cs
Normal file
45
Assets/Scripts/CameraMovement.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
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");
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/CameraMovement.cs.meta
Normal file
11
Assets/Scripts/CameraMovement.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b97e4b0c854344a5688f47e90e5ae90a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -26,11 +26,14 @@ public class PlayerBehavior : MonoBehaviour
|
||||
[SerializeField] private PlayerMovement playerController;
|
||||
[SerializeField] private StateController stateController;
|
||||
|
||||
Animator animator;
|
||||
|
||||
|
||||
void Start()
|
||||
{
|
||||
_rb = GetComponent<Rigidbody2D>();
|
||||
stateController = GameObject.Find("StateController").GetComponent<StateController>();
|
||||
animator = GetComponent<Animator>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
@@ -55,6 +58,19 @@ public class PlayerBehavior : MonoBehaviour
|
||||
{
|
||||
LetGoOfGrapple();
|
||||
}
|
||||
|
||||
Animate();
|
||||
}
|
||||
|
||||
void Animate() {
|
||||
// start walking
|
||||
if (playerInput.actions["Move"].WasPressedThisFrame()) {
|
||||
animator.SetBool("Walking", true);
|
||||
}
|
||||
// return to idle animation
|
||||
if (playerInput.actions["Move"].WasReleasedThisFrame()) {
|
||||
animator.SetBool("Walking", false);
|
||||
}
|
||||
}
|
||||
|
||||
void OnMove(InputValue value)
|
||||
|
||||
@@ -15,6 +15,7 @@ public class StateController : MonoBehaviour {
|
||||
|
||||
public void RespawnPlayer() {
|
||||
SetDeathCanvasActive(false);
|
||||
GameObject.Find("Main Camera").GetComponent<CameraMovement>().FindPlayer();
|
||||
Instantiate(player, spawnPoint.transform.position, spawnPoint.transform.rotation);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user