mirror of
https://github.com/DerTyp7/harvestdale-unity.git
synced 2025-10-30 13:07:10 +01:00
first commit
This commit is contained in:
34
Assets/Scripts/PlayerMovement.cs
Normal file
34
Assets/Scripts/PlayerMovement.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerMovement : MonoBehaviour
|
||||
{
|
||||
public float moveSpeed = 5f;
|
||||
private Rigidbody2D rb;
|
||||
private Animator animator;
|
||||
private Vector2 movement;
|
||||
|
||||
void Start()
|
||||
{
|
||||
rb = GetComponent<Rigidbody2D>();
|
||||
animator = GetComponent<Animator>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
movement.x = Input.GetAxisRaw("Horizontal");
|
||||
movement.y = Input.GetAxisRaw("Vertical");
|
||||
|
||||
animator.SetFloat("Horizontal", movement.x);
|
||||
animator.SetFloat("Vertical", movement.y);
|
||||
animator.SetFloat("Speed", movement.sqrMagnitude);
|
||||
|
||||
}
|
||||
|
||||
void FixedUpdate()
|
||||
{
|
||||
movement.Normalize();
|
||||
rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user