Files
FebGameJam/Assets/Scene 1 Assets/PlayerMovement.cs
T
2022-02-21 14:27:59 -06:00

38 lines
1.0 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public Movement controller;
public Animator animator;
public float runSpeed = 40f;
float horizontalMove = 0f;
bool jump = false;
bool crouch = false;
// Update is called once per frame
void Update() {
// Horizontal value is for the animation state machine. No code required, wow!
animator.SetFloat("Horizontal", Input.GetAxis("Horizontal"));
horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;
if (Input.GetButtonDown("Jump")) {
jump = true;
}
if (Input.GetKeyDown(KeyCode.LeftShift)) {
crouch = true;
} else if (Input.GetKeyUp(KeyCode.LeftShift)) {
crouch = false;
}
}
void FixedUpdate()
{
controller.Move(horizontalMove * Time.fixedDeltaTime, crouch, jump);
jump = false;
}
}